Next: , Previous: Sequence Iteration, Up: Drivers


2.1.3 Generalized Drivers

These are primarily useful for writing drivers that can also be used as generators (see Generators).

— Clause: for var next expr

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 of iterate, this termination should be done with terminate, which can be considered a synonym for finish (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)))
  

— Clause: for var do-next form

form 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 var next expr) is equivalent to (for var do-next (dsetq var expr)). (See Destructuring for an explanation of dsetq.)