【发布时间】:2016-07-31 15:38:19
【问题描述】:
我可以使用来自 While Loop Macro in DrRacket 的代码在 Racket 中使用“while”循环
(define-syntax-rule (while-loop condition body ...)
(let loop ()
(when condition
body ...
(loop))))
但是,我想在无限循环中使用 break,如下所示:
(define (testfn)
(define x 5)
(while-loop #t ; infinite while loop;
(println x)
(set! x (sub1 x))
(when (< x 0)
(break)))) ; HOW TO BREAK HERE;
如何在上面的无限循环中插入中断?感谢您的 cmets/answers。
【问题讨论】:
-
问题中的代码使用了命令式风格,这不是我们在Scheme中编写循环的方式。