The For and Foreach Statement
Explicit looping over an array is not often needed. If you need explicit looping, use the for statement:
for variable in expression
statements
end
The expression must evaluate to an array. The variable takes on successive elements of the array on each iteration of the loop. Assignment to the loop variable is legal but has an effect only for the remainder of that iteration. It does not alter the array.
Inside a for loop, the variable containing the array returns the value at the current iteration of the loop. This is redundant with the loop variable. For example, in
for i in $args log "$i" log "$args" end
the $i and $args are both equal for each iteration. The loop variable $i is there only for convenience.
The foreach statement lets you implicitly index an array, without the loop variable:
foreach expression
statements
end