Block Lambdas: break and continue

Axel Rauschmayer axel at rauschma.de
Sat Jan 14 13:19:32 PST 2012


Two possibilities (but I’m not entirely sure how much sense they make):

- Use a keyword that enables custom break and continue (problem: "for" clashes with iterators):
    for mycollection.each({ | x | if (x === 0) break })

- Standardize a BreakException. Then breaking isn’t the loop’s responsibility, any more. `continue` as an early return seems less important, because you can use break as follows:
    mycoll.forEach { | x |
        block: {
            if (x < 0) {
                break block; // "continue"
            }
            // do more with x here
        }
    }


-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



More information about the es-discuss mailing list