Next: Sequence Iteration, Up: Drivers

— Clause: **for**` var `

`&sequence`

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

`&sequence`

lambda-list keyword is a shorthand for these sequence keywords. They are:`from`

,`upfrom`

,`downfrom`

,`to`

,`downto`

,`above`

,`below`

and`by`

.`from`

provides the starting value forvarand defaults to zero.`to`

provides a final value and implies that the successive values ofvarwill be increasing;`downto`

implies that they will be decreasing. The loop terminates whenvarpasses 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 ofvarpast the final value.`below`

and`above`

are similar to`to`

and`downto`

, except that the loop terminates whenvarequals or passes the final value.If no final value is specified, the variable will be stepped forever. Using

`from`

or`upfrom`

will result in increasing values, while`downfrom`

will give decreasing values.On each iteration,

varis 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