www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: No fall-through for switch (WAS: Re: [Submission] D Slices)

reply bearophile < bearophileHUGS lycos.com> writes:
Andrej Mitrovic:

 Hey I've just realized something (well, it was in the docs, doh!), we
 can use already use "switch case;" to fallthrough to the next label
 without explicitly using goto:
 
 void main()
 {
     int x = 2;
     switch (x)
     {
         case 2:
             goto case;  // goto case 3;
             break;
 
         case 3:

This is good to have, but I don't find this syntax easy to understand, readable, natural. A " fallthrough" is much more explicit, but it's a very specialized thing. Bye, bearophile
Jun 13 2011
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Yeah I'd rather have it be something like "goto next", but then this
steals another keyword. Anyway you can always be explicit with your
gotos if you want readability.
Jun 13 2011