2.2 Iteration control

2.2.1 Using multiple iteration clauses

If you use multiple iteration clauses to control iteration, variable initialization and stepping occur sequentially by default. You can use theand construct to connect two or more iteration clauses when sequential binding and stepping are not necessary. The iteration behavior of clauses joined byand is analogous to the behavior of the Common Lisp macrodo with respect todo*.

In the following example, the variablex is stepped beforey is stepped; thus, the value ofy reflects the updated value ofx:

> (loop for x from 1 to 10 
        for y = nil then x 
        collect (list x y))
((1 NIL) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) (10 10))

In this example,x andy are stepped in parallel:

> (loop for x from 1 to 10 
        and 
        for y = nil then x 
        collect (list x y))
((1 NIL) (2 1) (3 2) (4 3) (5 4) (6 5) (7 6) (8 7) (9 8) (10 9))


The Loop Facility - 9 SEP 1996

Generated with Harlequin WebMaker