Loops/Downward for: Difference between revisions
Content deleted Content added
Line 670: | Line 670: | ||
((< n 0)) ; Break condition when negative |
((< n 0)) ; Break condition when negative |
||
(print n)) ; On every loop print value |
(print n)) ; On every loop print value |
||
</lang> |
|||
=== Using Tagbody and Go === |
|||
<lang lisp> |
|||
(let ((count 10)) ; Create local variable count = 10 |
|||
(tagbody |
|||
dec ; Create tag dec |
|||
(print count) ; Prints count |
|||
(decf count) ; Decreases count |
|||
(if (not (< count 0)) ; Ends loop when negative |
|||
(go dec)))) ; Loops back to tag dec |
|||
</lang> |
|||
=== Using Recursion === |
|||
<lang lisp> |
|||
(defun down-to-0 (count) |
|||
(print count) |
|||
(if (not (zerop count)) |
|||
(down-to-0 (1- count)))) |
|||
(down-to-0 10) |
|||
</lang> |
</lang> |
||