goto (outer) case
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Mon Feb 18 19:45:29 PST 2013
On Mon, 18 Feb 2013 22:30:48 -0500
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote:
>
> Hm.. wouldn't plain goto work:
>
> > final switch(foo)
> > {
> > case Foo.a:
> > final switch(bar)
> > {
> > case Bar.bar:
> > goto HORRIBLE_HACK;
> > break;
> > }
> > break;
> >
> > case Foo.b:
> > HORRIBLE_HACK:
> > break;
> > }
>
> Not sure, didn't test.
>
Maybe, but as you say it's a "horrible hack", and since my motivation
was for some code cleanup it's just kind of a wash. Ie, if I do that,
than it's debatable how much better that is than:
final switch(foo)
{
case Foo.a:
bool gotoB;
final switch(bar)
{
case Bar.bar:
gotoB = true;
break;
}
if(gotoB) goto case Foo.b;
break;
case Foo.b:
break;
}
Depends which you have more hatred towards: verbosity or goto.
In my case, I ended up just converting the inner switch to an if/else
chain, which actually isn't too bad since my inner enum/switch only had
three cases, one of which was just an empty "break;".
Some sort of "goto outer.case Foo.b;" could be handy, but I suspected
there probably wasn't such a thing.
More information about the Digitalmars-d-learn
mailing list