The do cycle in the racket has an interesting structure:
(do ([id init-expr step-expr-maybe] ...)
(stop?-expr finish-expr ...)
expr ...)
The documentation for r5rs gives an example:
(let ((x '(1 3 5 7 9)))
(do ((x x (cdr x))
(sum 0 (+ sum (car x))))
((null? x) sum)))
This operator returns 25, the sum of the elements in the loop. xin a loop, do is initialized to xin let, and then iteratively sets to cdritself each time through the loop. suminitialized to 0 and accumulates the value car xevery time through. A stop condition is when the iteration variable is empty and the return value is the sum.
, , . . - . , , ( ):
(define (find5 lst)
(do ([x lst (rest x)]
[found
((null? x) found)))
sum, or found. , first rest car cdr , . , .
(find5 '(1 2 3 4 6))
#f, . :
(find5 '(1 2 3 4 5 6))
#t.
do ?