8.16
while/until loops for Racket
(require while-until) | package: while-until |
This basically provides while, until, break and continue.
1 Example and usage
#lang racket/base (require while-until) (while (not (string=? (read-line) "quit")) (printf "quit? ")) (while #t (define input (read-line)) (unless (regexp-match #px"please" input) (printf "You didn't say please\n") (continue)) (when (regexp-match #px"quit" input) (break)))
#lang racket/base (require while-until) (require output) (define n 5) (while (> n 0) (dump n) (set! n (- n 1)) ) (define m 5) (until (< m 1) (dump m) (set! m (- m 1)) )
2 Reference
Repeat the evaluation of the body so long as test
is true.
Repeat the evaluation of the body so long as test
is false.
Break out of the innermost loop.
Restart the innermost loop.