do [[<var1> <init1> <step1>] ...] [<test> <expr> ...] <command> ... | R5RS |
Do is an iteration construct. It specifies a set of variables to be
bound, how they are to be initialized at the start, and how they are
to be updated on each iteration. When a termination condition is met,
the loop exits after evaluating the <expr> s.
Each iteration begins by evaluating If The region of the binding of a A (<var> <init> <var>)had been written. (do ((vec (make-vector 5)) (i 0 (+ i 1))) ((= i 5) vec) (vector-set! vec i i)) => #(0 1 2 3 4) (let ((x '(1 3 5 7 9))) (do ((x x (cdr x)) (sum 0 (+ sum (car x)))) ((null? x) sum))) => 25 |
dotimes [var count] <expression1> <expression2> ... | STKLOS Syntax |
dotimes [var count result] <expression1> <expression2> ... | STKLOS Syntax |
Evaluates the count expression, which must return an
integer and then evaluates the <expression> s once for each
integer from zero (inclusive) to count (exclusive), in order,
with the symbol var bound to the integer; if the value of
count is zero or negative, then the <expression> s are not
evaluated. When the loop completes, result is evaluated and its
value is returned as the value of the dotimes construction. If
result is omitted, dotimes result is void.
(let ((l '())) (dotimes (i 4 l) (set! l (cons i l)))) => (3 2 1 0) |
while <test> <expression1> <expression2> ... | STKLOS Syntax |
While evaluates the <expression> s until <test> returns a false
value. The value returned by this form is void
|
until <test> <expression1> <expression2> ... | STKLOS Syntax |
until evaluates the <expression> s until <while> returns a false
value. The value returned by this form is void
|