The general form for iterating over a sequence of numbers requires a variable and, optionally, one or more keywords that provide the bounds and step size of the iteration. The
&sequencelambda-list keyword is a shorthand for these sequence keywords. They are:
fromprovides the starting value for var and defaults to zero.
toprovides a final value and implies that the successive values of var will be increasing;
downtoimplies that they will be decreasing. The loop terminates when var passes the final value (i.e. becomes smaller or larger than it, depending on the direction of iteration); in other words, the loop body will never be executed for values of var past the final value.
aboveare similar to
downto, except that the loop terminates when var equals or passes the final value.
If no final value is specified, the variable will be stepped forever. Using
upfromwill result in increasing values, while
downfromwill give decreasing values.
On each iteration, var is incremented or decremented by the value of the sequence keyword
by, which defaults to 1. It should always be a positive number, even for downward iterations.
In the following examples, the sequence of numbers generated is shown next to the clause.(for i upfrom 0) => 0 1 2 ... (for i from 5) => 5 6 7 ... ; either from or upfrom is okay (for i downfrom 0) => 0 -1 -2 ... (for i from 1 to 3) => 1 2 3 (for i from 1 below 3) => 1 2 (for i from 1 to 3 by 2) => 1 3 (for i from 1 below 3 by 2) => 1 (for i from 5 downto 3) => 5 4 3