The @for directive allows for simple loops. The body of the directive is repeately macro expanded for different values of the loop variable(s), taken in sequence from the iteration list which is a comma separate list of values enclosed in square brackets.
A tuple of loop variables is supported, by using a comma separated list of identifiers in round brackets, and corresponding tuple values in the iteration list.
The loop variables can be regarded as macros that have local scope over the body of the @for directive.
Before translation | After translation |
---|---|
|
|
The iteration list is initially parsed as a single block of text enclosed in square brackets. This text is then macro expanded according to the macros defined at the point of invocation of the @for directive. Only then is the result parsed as a comma separated list. This approach makes the following example possible:
Before translation | After translation |
---|---|
|
|