My teacher keeps drilling into our collective heads that using the break command is harmful, and that if we wish to terminate a loop early it would be far better to create a boolean variable, set it to 0, and add a condition to the head of the loop, and set the boolean variable to 1 when a break is needed. Note that this way you actually have to check this every single loop (where it is not needed almost every time) as well as waste a command to reset the boolean in case it was set to true.
>>16-23
But Scheme has break and continue! They are called call-with-current-continuation! This should be portable R6RS code, but it is untested (define-syntax while
(lambda (stx)
(syntax-case stx ()
((while cond body body+ ...)
(with-syntax ((break (datum->syntax #'body 'break))
(continue (datum->syntax #'body 'continue)))
#'(let loop ()
(call-with-current-continuation
(lambda (break)
(let loop ()
(when cond
(call-with-current-continuation
(lambda (continue)
body body+ ...))
(loop)))))))))))
Yes, continue does the right thing in for (executes incr).
If you had read your SICP today, you would've known. You also would known that all the call-with-current-continuations can be optimized to call-with-escape-continuations.