Iteration: dolist, dotimes, do
(dolist (x '(a b c))
(print x))
(dolist (x '(1 2 3) :done) ; optional result form
(print x))
(dotimes (i 5) ; i from 0 to 4
(format t "~d " i))
(dotimes (i 3 (print "finished")) (print i))
;; do: general iteration (var init step), (end-test result), body
(do ((i 0 (1+ i))
(acc '() (cons i acc)))
((= i 5) (nreverse acc))) ; (0 1 2 3 4)
;; do*: sequential stepping
(do* ((x 1 (* x 2))
(y x x))
((> x 100) y))
;; loop without keywords: infinite until return
(let ((n 0))
(loop
(incf n)
(when (> n 3) (return n)))) ; 4