Next: The Outer Subsequent For, Previous: The Reverse For, Up: The For Statement [Index]
The ‘for’ binding variables may be declared by the statement, in the same way variables are introduced, with the type preceding the name. The variables scope is restricted to the declaring ‘for’. No function pointers declarations are recognized.
One declared variable bound ‘for’:
for (text s in record("A", 0, "B", 1)) { o_(s, "\n"); }
Two declared variables bound ‘for’:
for (integer p, integer a in list(1, 2, 4, 8)) { o_(p, " ", a, "\n"); }
Mixed declarations bound ‘for’:
integer v; record r; text s; r = record("A", 0, "B", 1); for (s, integer x in r) { o_(s, " ", x, "\n"); } for (text i, v in r) { o_(i, " ", v, "\n"); } for (, integer x in r) { o_(x, "\n"); }
If no type is given for the second binding variable then if a variable of the same name can be looked up in the scope of the for statement, the variable is used, otherwise and only if a type has been given for the first binding variable the second variable is taken to be of the same type as the first.
for (integer p, a in list(1, 2, 3)) { o_(p, " ", a, "\n"); }
has a of type ‘integer’, the type of p.