Skip to content

Latest commit

 

History

History
47 lines (40 loc) · 614 Bytes

loops.md

File metadata and controls

47 lines (40 loc) · 614 Bytes

Loops

(loop for i from 1 to 3
   do (princ i)
      (fresh-line))
;; => 1
;;    2
;;    3
;;
;;
;;    NIL
  • A simple loop.
(loop for n from 0
   do (princ n)
     (fresh-line)
     (return))
;; => 0
;;
;;
;;    NIL
  • Loops can go on forever (there is no to in this loop).
  • We can break out of a loop by using return function.
(loop for n from 0 to 5
   do
     (unless (= (mod n 2) 0)
       (princ n))
     (fresh-line))
;; => 1
;;    3
;;    5
;;
;;
;;    NIL