Simple Loops using do


; Print integers from 1 to n using do
(define (printto n)
  (do ( (i  1  (1+ i)) )
      ( (> i n)  #f )
    (write i)
    (newline)
  ) )

> (printto 3) 1 2 3 #f


; Sum integers from 1 to n using do
(define (sumto n)
  (do ( (i   1 (1+ i))
        (sum 0       ) )
      ( (> i n) sum )
    (set! sum (+ sum i))
  ) )

> (sumto 10) 55

Contents    Page-10    Prev    Next    Page+10    Index