break switch?
bearophile
bearophileHUGS at lycos.com
Sun Jun 9 17:05:37 PDT 2013
Timon Gehr:
> Are you aware that the following works?
>
> void main(){
> import std.stdio;
> enum Foo{foo1,foo2}
> int[5] data;
> Foo f;
> Lswitch:switch(f){
> case Foo.foo1:
> foreach (x;data)
> if(x==10)
> break Lswitch;
> writeln("10 not found.");
> data[0] = 10; // Put the missing 10.
> break;
>
> default:
> break;
> }
> }
Of course I wasn't aware of that :-) I have never seen that in
docs, or D code. It's an acceptable solution, better than the
goto.
Thank you,
bearophile
More information about the Digitalmars-d
mailing list