Comment

Comment by brabel

I suspect you'll love Common Lisp's LOOP: https://gigamonkeys.com/book/loop-for-black-belts

Example:

    (loop repeat 8
               ;; init x, then decide how to "prepare" next  iteration
               for x = 0 then (+ (* 2 x) 1)
               collect x)

    (0 1 3 7 15 31 63 127)
You can insert a condition check in the middle, of course:

    (loop repeat 8
               for x = 0 then (+ (* 2 x) 1)
               ;; but stop if x gets too big
               while (< x 100)
               collect x)

    (0 1 3 7 15 31 63)
And much, much more. It's the ultimate loop construct.
parent brabel 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton