Add 'break' block to exit loops

Issue #53 new
Turgut Guneysu created an issue

Hi John,

I have been using the for i in __ block to process lists within lists very effectively. It lets me iterate through the items easily.

However, I noticed that there is no corresponding BREAK command to early exit interim levels of the loops if needed.

It is very useful to have a way to bypass certain values.

One cannot bypass entries even with an IF compare.

Any way to make such a command to facilitate better list processing?

Thanks, TG

Comments (3)

  1. John Maloney repo owner

    Agreed the a ‘break’ (or ‘exit loop’) block would be useful. You can sort of get this behavior by putting the loop into function and using ‘return’ to exit the entire function (as well as the loop) early (e.g. when it finds a given value in the list). The Smalltalk-80 language didn’t have a “break” command this technique was a common programming pattern.

    However, will keep this around as a feature request.

  2. Bernat Romagosa

    Snap! does the same thing. Reporting from inside a loop will break out from it and stop the whole task.

    Breaking from the loop and continuing from there is different, though. I suspect Turgut wants this second feature, present in other mainstream languages.

    I’m inclined to think that a program that needs to break from a loop is a not well thought out program, though I could change my opinion if I saw examples where that would be the most elegant way to proceed. I can’t think of any right now…

  3. Log in to comment