HomeManualTopicsTypesSymbols

std::from_to_by

a loop iterating over a sequence of values

Parameters

from
the value to use for the first invocation of *body*
to
the value to use for the last invocation of *body*
by
the incrementation/decrementation value
body
the statement sequence to execute for each value
finally (default: pass)
code to execute after the last iteration

Results

None

Description

The starting value is incremented by the given step after each invocation of body.

The type of the first and last value need not be integers but can be of arbitrary types that support adding the given step value.

The loop terminates as soon as the current value is greater than last. (The body will only be called for values that are less than or equal to last.)

If first is greater than last then the loop body will not be called at all!

The body is called with a single argument (the current value).

To start the next iteration of the loop a tail call to the next-function has to be performed.

To exit from the loop a tail call to the break-function has to be performed or one or more results have to be returned.

Example

from_to_by 1 10 2: (i) println! i " x " i " = " i*i next!

Output

1 x 1 = 1 3 x 3 = 9 5 x 5 = 25 7 x 7 = 49 9 x 9 = 81

Topic

Loops

See also

std::loop a simple "loop"
std::while a "while" loop
std::while_not a "while" loop
std::repeat invoke a statement sequence for a specific number of times
std::from_to a loop iterating over a sequence of values