Next: , Previous: , Up: The For Statement   [Index]


7.3.4 The Bound Subsequent For

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
-eqpicks the exactly matching position
-ltpicks the last less than position
-lepicks the last less or matching (equal) position
-gepicks the first greater or matching (equal) position
-gtpicks 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