Next: The Leave Clause, Previous: The Outer Subsequent For, Up: The For Statement [Index]
The bound subsequent ‘for’ statement allows for collection traversals with an arbitrary entry point. The traversal start is set by the first binding variable, the one giving the position. The variable cannot be skipped, nor can it be declared by the statement.
The bound subsequent ‘for’ statement replaces the initial clause of the end to end ‘for’ traversal, the one setting for the initial position, with one that seeks the collection for a position matching the value of the first binding variable by a certain criterion.
The position matching criterion is set right after the leading parenthesis, in the form of one of the literals:
Action on the value of the first binding variable | |
---|---|
‘-eq’ | picks the exactly matching position |
‘-lt’ | picks the last less than position |
‘-le’ | picks the last less or matching (equal) position |
‘-ge’ | picks the first greater or matching (equal) position |
‘-gt’ | picks the first greater than position |
If no position within the collection can be matched, the statement completes (without executing the braces block once).
The bound subsequent ‘for’ statement is defined per data types combination.
The program:
text p; p = "C"; for (-ge p, integer a in record("A", 0, "B", 1, "C", 2, "D", 3, "E", 4)) { o_(a, "\n"); }
outputs:
2 3 4