The special LOOP NAMED foo
syntax allows you to create a loop that you can exit early from. The exit is performed using return-from
, and can be used from within nested loops.
The following uses a nested loop to look for a complex number in a 2D array:
(loop named top
for x from 0 below (array-dimension *array* 1)
do (loop for y from 0 below (array-dimension *array* 0))
for n = (aref *array* y x)
when (complexp n)
do (return-from top (values n x y))))