LoopStatement ::=
"FOR" Ident "IN" LoopSetDefinition
"DO" StatementList "END" |
"FOR" "IN" LoopSetDefinition
"DO" StatementList "END"
LoopSetDefinition ::=
Expression ".." Expression |
Expression
A RainCode loop statement repeats the execution of a statement list for all values of a free variable taken from a reference set. This free variable does not have to be defined prior to the loop. If the free variable's identifier is not defined (second form in the grammar presented above), the predefined anonymous identifier X is to be used.
Hence, a statement such as:
FOR IN 1..10 DO OUT.WriteLn(X); END;
is equivalent to:
FOR X IN 1..10 DO OUT.WriteLn(X); END;
The reference set can be of two forms:
7..2.