request switch statement with common block

JS js.mdnq at gmail.com
Sat Aug 3 10:21:41 PDT 2013


On Saturday, 3 August 2013 at 16:16:24 UTC, Ary Borenszweig wrote:
> On 8/3/13 11:38 AM, JS wrote:
>>
>> switch (cond)
>>     common: always executed code here
>>     case A : etc...
>>     ....
>> }
>>
>> instead of
>>
>> if (cond) { always executed code here  }
>> switch (cond)
>>     case A : etc...
>>     ....
>> }
>>
>> which requires modification of the condition twice when 
>> necessary
>
> Do you mean this?
>
> switch(cond) {
>   case A:
>     common_code();
>     // something
>   case B:
>     common_code();
>     // something else
> }
>
> (common_code() must not be executed if it doesn't hit any 
> switch case)

exactly


More information about the Digitalmars-d mailing list