Suggestion: new switch statement

Kristian kjkilpi at gmail.com
Mon Aug 21 04:05:30 PDT 2006


On Mon, 21 Aug 2006 13:06:49 +0300, Jeff <psychobrat at gmail.com> wrote:

> How about allowing:
>
> switch (val) {
>      case (1) {
> 	doX();
>      } case (2, 3) {
>          doY();
>      } default {
>          doZ();
>      }
> )
>
> Or would this create some horrible syntactic ambiguities? Or, on the  
> other hand, it could just be too damn ugly. ;)

Actually I also thought about that very syntax. :) However, I guess that  
there are people out there that are not so fond of having more curly  
brackets... In a way it'd fit the structure of the language, though.

But, as you mentioned, it could confuse people and generate more bugs.  
Also note that this is ok in D:

void func(int val) {
     switch(val) {
         case 1:
             doX();
             break;

         case 2:
             {
             int b = 2;  //a local variable inside a block
             doY(b);
             }
             break;
     }
}

So, I think it would be better just use different statement. (And for a  
compiler, it'd be simple to implement.)


Heheh, I just tested the switch statement, and guess what? I forgot to put  
the break statements at the end of cases...!!



More information about the Digitalmars-d mailing list