Mel Script - the for-in loop




A for-in loop is a specialised loop used to iterate over an array. If you are only reading the contents of an array, then you should use the for-in loop to do it. The for-in loop will not allow you to edit an array unfortunately :(

The general form for a for-in loop is as follows :




		for( <variable> in <array> ) {
			// action to repeat




Within the loop, you are free to use <variable> instead of needing to access an array element. Hopefully this should make your scripts slightly easier to read!





Example 1 : A basic for-in example

A for-in loop is used to print the contents of an array



		// the array to iterate through
		float $data_array[] = {0.13,0.41,0.32,8.93,10.4,2.34,0.56};

		// each time the loop repeats, $item will hold the next element in the array
		for( $item in $data_array )
			// print the value
			print($item + "\n");