About switch case statements...
Chad J
chadjoan at __spam.is.bad__gmail.com
Sun Nov 15 11:19:50 PST 2009
Chad J wrote:
>
> There has to be a better way to do fall-through.
>
> Maybe...
>
> switch(foo)
> {
> case 0;
> case 1; bar = baz; // Executed if foo == 0
> case 2:
> doSomething(bar); // Executed for foo ∈ {0,1,2}
> break; //required for compile success.
> }
or if you want it to look nicer, maybe introduce an arrow token:
switch(foo)
{
case 0 ->
case 1 -> bar = baz; // Executed if foo == 0
case 2:
doSomething(bar); // Executed for foo ∈ {0,1,2}
break; //required for compile success.
}
It has these advantages:
* Fall-through behavior is explicit.
* Fall-through notation requires no extra lines of source, and only a
couple extra columns.
Sigh, I didn't want to discuss syntax, but that response... it makes me
want to solve problems, to say the least.
More information about the Digitalmars-d
mailing list