How can I define a label inside a switch?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 14 10:27:18 PST 2014


On Sun, 14 Dec 2014 18:24:39 +0000
MachineCode via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> I used to do it in C but in D it's giving this compile error 
> message:
> 
> > switch case fallthrough - 'use goto case;' if intended
> 
> Here's the code:
> 
> > switch(value) {
> > // alof of cases here
> > // ...
> > white: // regular label
> >			case 'a': case 'c':
> >			case 'd': case 'k':
> >				do_something();
> >				break;
> >  case 'e':
> >        do_something2();
> >         break;
> >  default: assert(0);
> > }
> 
> How is it fall through if there's a break? does D switch differ 
> from C in any way?
why do you need that? you can use literally what compiler told you:
`goto case 'a';` for example.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141214/56eebe7e/attachment.sig>


More information about the Digitalmars-d-learn mailing list