RETURN

RETURN works within DOTIMES and DOLIST, and allows quiting the loop with given result. It expects one argument, which will be evaluated and the result returned from the loop. If none arguements are given, the RETURN quits the loop with NIL.

>(dotimes (i 10)
    (if (= i 3) (return "have 3")) 
    (print "beep"))
"beep"
"beep"
"beep"
"have 3"

When more than one arguments are given, only the first one is evaluated, the RETURN still quits the loop returns the value, but warning to the user is issued. When used outside a loop, RETURN still evaluates the first argument and gives its value, and warns the user.

>(return (+ 2 2))            ; wrong use of RETURN
;RETURN used outside loop. Has no effect.
4

See also DOTIMES, DOLIST