for-in

 
 
 

The most common use of a for loop is to iterate over every element of an array. MEL has a special form of the for loop that lets you do this very easily.

The for-in loop has the form:

for (array-element in array) {
	statement;
	statement;
	...
}
string $carType[3] = {"Porsche", "Ferrari", "BMW"};
string $car;
for ($car in $carType) {
	print("I want a new ");
	print($car + ".\n");
}

This prints the following lines in the Script Editor:

I want a new Porsche.
I want a new Ferrari.
I want a new BMW.

The loop executes three times, once for each array element in $carType.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License