Simple Loops using while

A loop from 1 to n:


; Print integers from 1 to n
(define (printn n)
  (let ((i 1))
    (while (<= i n)
      (write i)
      (newline)
      (set! i (1+ i)))))  ; don't forget this!!

> (printn 3)
1
2
3
#[undefined]

Design pattern for a loop that looks for something: (let ((done #f))
      (while (not done)
      ...
      (if condition
      (set! done #t))
      ... ) )

Contents    Page-10    Prev    Next    Page+10    Index