Next: , Previous: Gathering Clauses, Up: Clauses

2.4 Control Flow

Several clauses can be used to alter the usual flow of control in a loop.

Note: the clauses of this and subsequent sections don't adhere to iterate's usual syntax, but instead use standard Common Lisp syntax. Hence the format for describing syntax subsequently is like the standard format used in the Common Lisp manual, not like the descriptions of clauses above.

— Clause: finish

Stops the loop and runs the epilogue code.

— Clause: leave &optional value

Immediately returns value (default nil) from the current iterate form, skipping the epilogue code. Equivalent to using return-from.

— Clause: next-iteration

Skips the remainder of the loop body and begins the next iteration of the loop.

— Clause: while expr

If expr ever evaluates to nil, the loop is terminated and the epilogue code executed. Equivalent to (if (not expr) (finish)).

— Clause: until ~expr~

Equivalent to (if expr (finish)).

— Clause: if-first-time then &optional else

If this clause is being executed for the first time in this invocation of the iterate form, then the then code is evaluated; otherwise the else code is evaluated.

(for var first expr1 then expr2) is almost equivalent to

       (if-first-time (dsetq var expr1)
                      (dsetq var expr2))

The only difference is that the for version makes var available for use with for... previous.