common-lisp Simple loop


Example

The loop macro has two forms: the "simple" form and the "extended" form. The extended form is covered in another documentation topic, but the simple loop is useful for very basic loop.

The simple loop form takes a number of forms and repeats them until the loop is exited using return or some other exit (e.g., throw).

(let ((x 0))
  (loop
     (print x)
     (incf x)
     (unless (< x 5)
       (return))))

0 
1 
2 
3 
4 
NIL