Re: Break Statements similar to C or C++



On 2007-05-31 00:31:04 -0400, "gokul.mano@xxxxxxxxx" <gokul.mano@xxxxxxxxx> said:

Is there any function to break from a loop as we have break in C or C+
+.

CL-USER 22 > (loop named foo
for bar = 0 then (random 100)
do (if (> bar 76) (return-from foo bar) (print bar)))

0
72
25
16
69
63
9
63
79

CL-USER 23 > (loop for bar = 0 then (random 100)
do (print bar)
when (> bar 76)
return (values))

0
24
11
21
47
60
53
21
78

CL-USER 24 > (loop for bar = 0 then (random 100)
do (print bar)
thereis (> bar 76))

0
44
97
T

CL-USER 25 > (catch 'baz
(loop for bar = 0 then (random 100)
do (print bar)
(if (> bar 76)
(throw 'baz bar))))

0
73
71
29
36
20
34
0
93
93

CL-USER 26 > (tagbody
(loop for bar = 0 then (random 100)
do (print bar)
(if (> bar 76)
(go baz)))
baz)

0
48
17
91
NIL

.