[racket] Exiting a for loop early
On Tue, Jul 19, 2011 at 8:24 PM, Justin Zamora <justin at zamora.com> wrote:
> Is there a built in way to exit the various kinds of for loops early?
> I've been using code like:
>
> (let/ec break
> (for ([i (in-range 1 100)]
> #:when (condition? i))
> (break i))))
>
> Is there a better way?
>
> Justin
It sounds like you want the stop-before and stop-after functions, or
possibly the for/first loop.
http://docs.racket-lang.org/reference/sequences.html?q=sequence#(def._((lib._racket/private/base..rkt)._stop-before))
http://docs.racket-lang.org/reference/sequences.html?q=sequence#(def._((lib._racket/private/base..rkt)._stop-after))
http://docs.racket-lang.org/reference/for.html?q=for/first&q=sequence#(form._((lib._racket/private/base..rkt)._for/first))
--Carl