Next: Generators, Previous: Sequence Iteration, Up: Drivers
These are primarily useful for writing drivers that can also be used as generators (see Generators).
var is set to expr each time through the loop. Destructuring is performed. When the clause is used as a generator, expr is the code that is executed when
(next
var)
is encountered (see Generators). expr should compute the first value for var, as well as all subsequent values, and is responsible for terminating the loop. For compatibility with future versions ofiterate
, this termination should be done withterminate
, which can be considered a synonym forfinish
(see Control Flow).As an example, the following clauses are equivalent to
(for i from 1 to 10)
:(initially (setq i 0)) (for i next (if (> i 10) (terminate) (incf i)))
do-next
formform is evaluated each time through the loop. Its value is not set to var; that is form's job. var is only present so that
iterate
knows it is a driver variable.
(for
varnext
expr)
is equivalent to(for
vardo-next (dsetq
var expr))
. (See Destructuring for an explanation ofdsetq
.)