No more fall through in case statement?

Mike vertex at gmx.at
Thu Jan 3 08:12:51 PST 2008


On Thu, 03 Jan 2008 16:43:52 +0100, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> I'm not super excited about there being such a subtle difference with the
> colon (if you automatically put a colon without thinking about it, then  
> the
> break statement is required, meaning a very subtle bug), but other than
> that, I like the idea.  Why not make it more obvious?:
>
> case (x, y, z) // similar to case x: case y: case z:
> {
> }
> /* else case(a, b, c) ? */
>
> -Steve

I want to add two things:

(1) When using () after case, the {} should be optional, like in an if:

case (1) foo();
case (2, 3)
{
     foo();
     bar();
}

(2) continue should be used for fall through behavior:

case (1) foo();
case (2, 3)
{
     if (x == 3) continue 1;
     bar();
}

We could even get rid of "default" and label the default case as "else" -  
saving a keyword :)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list