Next: The Bound Subsequent For, Previous: For Declarations, Up: The For Statement [Index]
The outer subsequent ‘for’ statement does away with the initial setting of the binding variables. If the regular ‘for’ is equivalent to:
if (set for initial position in data collection) {
do {
} while (set for the next position);
}
the subsequent ‘for’ is:
do {
} while (set for the next position);
The braces block is executed once without the binding variables being set, not bound to, and possibly out of the collection being traversed.
Its syntax has a ‘+’ sign following the initial opening parenthesis.
for (+a in collection) {
}
for (+a, b in collection) {
}
The first binding variable is required. No declarations are allowed by the syntax.
The program:
integer a, b;
a = 4;
b = 2;
for (+a, b in list(0, 1, 4, 9, 16, 25)) {
o_form("~x~\n", a, b);
}
outputs:
4x2 5x25
The outer subsequent ‘for’ statement is defined for every data types combination for which a plain ‘for’ statement is defined, in the direction in which the latter is defined (forward or backward).