next up previous contents index
Next: high,low Up: IntegerSegment Previous: by,step   Contents   Index


generator


Usage

for x in s repeat { ...}
for x in generator s repeat { ...}


Signature

generator: % $\to$ Generator Z


Parameter Type Description
s % a segment


Description

This functions allows a segment to be iterated. This generator yields the integers of s in succession.


Example

The following code computes the sum of all the positive even machine integers that are smaller than $n$:
evenSum(n:MachineInteger):MachineInteger == {
    s := 0;
    for x in 2..prev(n) by 2 repeat s := s + x;
    s;
}



Manuel Bronstein 2004-06-28