
2.7 Unconditional execution
doing Unconditional Execution Clause Construct
do[ing] [expr]*
do construct simply evaluates the specified expressions wherever they occur in the expanded form ofloop.
do,initially, andfinally are the only loop keywords that take an arbitrary number of forms and group them as if by using an implicitprogn.
do when no control action other than execution is required.
;; Print some numbers.
> (loop for i from 1 to 3
do (print i))
1
2
3
NIL
;; Print numbers and their squares.
;; The DO construct applies to multiple forms.
> (loop for i from 1 to 3
do (print i)
(print (* i i)))
1
1
2
4
3
9
NIL
return Unconditional Execution Clause Construct
return expr
return construct terminates a loop and returns the value of the specified expression as the value of the loop. This construct is similar to the Common Lisp special formreturn-from and the Common Lisp macroreturn.
return construct for backwards compatibility with older loop implementations.
return construct returns immediately and does not execute anyfinally clause that is given.
;; Signal an exceptional condition.
> (loop for item in '(1 2 3 a 4 5)
when (not (numberp item))
return (cerror "enter new value"
"non-numeric value: ~s" item))
>>Error: non-numeric value: A
EVAL:
Required arg 0 (EXPRESSION): (LOOP FOR ITEM IN (QUOTE (1 2 3 A 4 5))
WHEN (NOT (NUMBERP ITEM)) RETURN (CERROR "enter new value"
"non-numeric value: ~s" ITEM))
:C 0: enter new value
:A 1: Abort to Lisp Top Level
-> :a
Abort to Lisp Top Level
Back to Lisp Top Level
;; The previous example is equivalent to the following one.
> (loop for item in '(1 2 3 a 4 5)
when (not (numberp item))
do (return
(cerror "enter new value"
"non-numeric value: ~s" item)))
>>Error: non-numeric value: A
EVAL:
Required arg 0 (EXPRESSION): (LOOP FOR ITEM IN (QUOTE (1 2 3 A 4 5))
WHEN (NOT (NUMBERP ITEM)) DO (RETURN (CERROR "enter new value"
"non-numeric value: ~s" ITEM)))
:C 0: enter new value
:A 1: Abort to Lisp Top Level
-> :a
Abort to Lisp Top Level
Back to Lisp Top Level

Generated with Harlequin WebMaker