Inside the switch statement
Steve Schveighoffer
schveiguy at yahoo.com
Wed Jun 10 21:04:20 PDT 2009
On Tue, 09 Jun 2009 19:35:51 +0200, Saaa wrote:
>>> 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 :)
case value1:
code1();
goto case value2; // already valid D code
// or
goto case; // already valid D code
case value2:
code2();
break;
Should be uncommon enough that the extra clarification is warranted IMO.
I believe I've fallen victim to accidental fall-throughs more than I've
found uses for them...
vote++
-Steve
More information about the Digitalmars-d-learn
mailing list