for each

for each statements iterate over a collection, executing a block of statements for each element.

Syntax

for each <type> in <expression> do 
    <statements> 
end
type
The variable name for the current element.
expression
The collection to iterate over.
statements
The code block executed for each element.
end
All for each statements must terminate with the end keyword.

Example

The following example iterates through a list of numbers:

for each number in {1, 2, 3, 4, 5} do
    set result to result + this number + " ";
end

// Output: "1 2 3 4 5 "
It works as follows:
  1. Iterates through each element in the collection {1, 2, 3, 4, 5}.
  2. Assigns the current element to number.
  3. Appends the value to result with a space.
  4. Repeats for all elements in order.