Inside the switch statement

Saaa empty at needmail.com
Tue Jun 9 10:35:51 PDT 2009


>> What kind of fall-throughs were these?
>>
>> A:
>>
>> case value1:
>> case value2:
>> case valueN:
>>     code1();
>>     break;
>>
>> B:
>>
>> case value1:
>>     code1();
>> case value2:
>>     code2();
>>     break;
>
> The solution is to forbid fallthrough, and change the switch syntax:
>
> switch(value) {
>   case 1:
>   case 2:
> // something
> break;
> }
>
> gives: Error, missing break at the end of case1.
>
> But:
>
> switch(value) {
>   case 1, 2:
> // something
> break;
> }
>
> works as expected.
>
> What's wrong with that?

Doesn't support B :)

How about a warning instead? 




More information about the Digitalmars-d-learn mailing list