Next: , Up: loops comprehensions   [Index]


1.16.2.1 Simple loops

Syntax: do-ec ?qualifier ... command

Evaluate the command exactly once for each binding in the sequence defined by the qualifiers. If there are no qualifiers command is evaluated exactly once. The expression is evaluated for its side–effects only. The result of the comprehension is unspecified.

(let ((x 0))
  (do-ec                ;no qualifiers
    (set! x (+ x 1)))
  x)
⇒ 1

(let ((x 0))
  (do-ec (:range i 10)  ;i from 0 to 9
    (set! x (+ x 1)))
  x)
⇒ 10

(let ((x 0))
  (do-ec (:range i 0)   ;loops zero times
    (set! x (+ x 1)))
  x)
⇒ 0

(let ((x 0))
  (do-ec (:range n 10)  ;n from 0 to 9
         (:range k n)   ;k from 0 to n
    (set! x (+ x 1)))
  x)
⇒ 45