goto (outer) case

Steven Schveighoffer schveiguy at yahoo.com
Mon Feb 18 19:30:48 PST 2013


On Mon, 18 Feb 2013 20:59:37 -0500, Nick Sabalausky  
<SeeWebsiteToContactMe at semitwist.com> wrote:

> Consider these nested switches:
>
> ---------------------------
> enum Foo {a, b}
> enum Bar {bar}
>
> auto foo = Foo.a;
> auto bar = Bar.bar;
>
> final switch(foo)
> {
> case Foo.a:
>     final switch(bar)
>     {
>     case Bar.bar:
>         XXXXXX
>         break;
>     }
>     break;
>
> case Foo.b:
>     break;
> }
> ---------------------------
>
> Without adding extra code anywhere else, is there anything I can stick
> in for XXXXXX to get execution to jump to "case Foo.b:"?
>
> Doing "goto case Foo.b;" doesn't work. It just gives a compile error
> that a Foo can't be implicitly converted to Bar.
>
> This ability isn't critical, of course, but it would help clean up some
> code I have.
>

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.

-Steve


More information about the Digitalmars-d-learn mailing list