Sugaring the switch()

Jeff Watkins watkins at apple.com
Fri Sep 5 22:34:35 PDT 2008


What's wrong with the current syntax:

switch (foo)
{
     case 1:
     case 2:
     case 3:
         // stuff
         break;

     case 4:
     case 5:
         // more stuff
         break;
}

I'll agree it's not as compact, but as David pointed out the comma  
version is already valid with an alternate meaning.

On 5 Sep, 2008, at 9:12 PM, Michael Haufe wrote:

> I didn't see this mentioned yet, so I'd like to propose implementing a
> feature available in VB.NET that I think would be valuable in ES. Some
> sugar for the switch() block:
>
> switch(foo){
>    case 1,2,3:
>        //stuff...
>    break;
>    case a,b,c:
>        //stuff...
>    break;
> }
>
> Would be equivalent to:
>
> switch(foo){
>    case 1:
>        //stuff...
>    break;
>    case 2:
>        //stuff...
>    break;
>    case 3:
>        //stuff...
>    break;
>    case a:
>        //stuff...
>    break;
>    case b:
>        //stuff...
>    break;
>    case c:
>        //stuff...
>    break;
> }
>
> _______________________________________________
> Es-discuss mailing list
> Es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080905/135a29d1/attachment.html 


More information about the Es-discuss mailing list