Simkin for each Statement


This statement allows you to iterate over a collection, with an optional qualifier.

The statement has 2 main sections:

  1. the for each section specifies what to enumerate over, and which variable to bind each item to

  2. this is followed by a block of statements to be executed for each item
Here is an example of unqualified iteration:
// looks at each item in the collection, 
// the variable "item" will receive each item in the iteration
for each item in collection {
 trace(item.name);
}
In this example, a qualifier is added:
// looks at each "simple" item in the collection, 
// the variable "simple_item" will receive each item in the iteration
for each simple simple_item in collection {
 trace(item.name);
}
The underlying code interprets the qualifier in whatever way is appropriate to it.

Note: you have to use the braces "{" and "}" to surround the statements after the for clause.