Previous: always-never-thereis, Up: End-Test Control [Contents][Index]
The macro loop-finish
terminates iteration normally and returns any
accumulated result. If specified, a ‘finally’ clause is evaluated.
In most cases it is not necessary to use loop-finish
because other loop
control clauses terminate the loop. Use loop-finish
to provide a normal exit
from a nested condition inside a loop.
You can use loop-finish
inside nested Lisp code to provide a normal exit from
a loop. Since loop-finish
transfers control to the loop ‘epilogue’, using
loop-finish
within a ‘finally’ expression can cause infinite looping.
Implementations are allowed to provide this construct as a local macro by using
macrolet
.
;;; Print a date in February, but exclude leap day. ;;; LOOP-FINISH exits from the nested condition. (loop for date in date-list do (case date (29 (when (eq month 'february) (loop-finish)) (format t "~:@(~A~) ~A" month date))))
;;; Terminate the loop, but return the accumulated count. (loop for i in '(1 2 3 stop-here 4 5 6) when (symbolp i) do (loop-finish) count i)
;;; This loop works just as well as the previous example. (loop for i in '(1 2 3 stop-here 4 5 6) until (symbolp i) count i)