request switch statement with common block

dennis luehring dl.soluz at gmx.net
Sat Aug 3 08:47:44 PDT 2013


Am 03.08.2013 16:38, schrieb JS:
>
> 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
>

switch does get an value not an condition in its scope (the cases are 
the evaluators)

what is the sense of common in this switch example?

switch(my_enum)
{
   common: printf("common");
   case A: printf("A"); break;
   case B: printf("B"); break;
}

why not write it like...

printf("common");
switch(my_enum)
{
   case A: printf("A"); break;
   case B: printf("B"); break;
}

cases are equal-to-value evaluators - so what is the evaluation of "common"?

i don't get it, and speaking about fall-through principle is common 
always fired on start, on end or what?



More information about the Digitalmars-d mailing list