foreach ... else statement

bearophile bearophileHUGS at lycos.com
Mon Jan 5 00:46:08 PST 2009


BCS:
> I think your expectation would be a good feature but I can't really see else 
> being the right keyword to use. How about "finally"? Or another option with 
> scope(*) like "fallthrough"?

The good thing of "else" is that you don't need a new keyword. But it's not intuitive. A better keyword may make the code much more readable. For example:

foreach (key, f; fooAA)
    if (f.someFlag && key in barAA && f.someVal > barAA[key].someVal)
        break;
    unbroken
        writefln("Missing!");

It looks a little silly, but I think it's easy to understand the meaning :-)
Bye,
bearophile



More information about the Digitalmars-d mailing list