- Up - | Next >> |
In order to provide convenient syntax for loops, two new keywords have been introduced in Mozart 1.1.0: for
and do
. Thus, a new statement is introduced in the Oz language and its syntax is:
for
Iteratorsdo ... end
where Iterators is a sequence of 1 or more iterators. An iterator has the form: X in
Generator where Generator describes how to generate the successive values for variable X, which is a variable local to the loop. The loop terminates as soon as one of the generators runs out of values.
Iterators
These are the iterators officially supported in Mozart 1.1.0.
X in
L iterates over the elements of list L. At each iteration, X
is bound to the next element in L. The generator runs out when all elements in L have been consumed.
X in
I..
J iterates over the integers from I to J (both inclusive). At each iteration X
is bound to the next integer in this sequence. More precisely, the sequence starts at I and proceeds by increments of 1 as long as it remains less than or equal to J.
- Up - | Next >> |