;;;  File: IterSum.lsp
;;; 
;;;  Sum the integers between n and 0
;;; 
;;;  Author:  Bary W Pollack
;;;  Date:    Feb. 2, 2003
;;; 
;;;  Demonstrate use of do (iteration)
;;;  and contrast with recursion
;;; 

;;;  --------------------------------------------------------------
;;;  iterative top-level driver

(defun iterSum (max)
    (do ((i max (1-  i))     ; i decrements
         (sum 0 (+ i sum)))
        ((<= i 0) sum) ))

(terpri)

(princ "Sum of integers from 3 to 0:   ")
(print (iterSum 3))

(princ "Sum of integers from 10 to 0:  ")
(print (iterSum 10))

(princ "Sum of integers from 100 to 0: ")
(print (iterSum 100))

;;;  --------------------------------------------------------------
;;;  recursive driver

(defun recurSum (max)
    (if (<= max 0)
            0
            (+ max (recurSum (1- max))) ))

(terpri)

(princ "Sum of integers from 3 to 0:   ")
(print (recurSum 3))

(princ "Sum of integers from 10 to 0:  ")
(print (recurSum 10))

(princ "Sum of integers from 100 to 0: ")
(print (recurSum 100))

