switch break/fall (last minute request ... )
mike
vertex at gmx.at
Tue Dec 26 16:03:11 PST 2006
Am 26.12.2006, 23:26 Uhr, schrieb Hasan Aljudy <hasan.aljudy at gmail.com>:
> I feel that fighting this common source of bug should've been one of the
> first things that D had done.
>
I've once suggested this syntax:
' switch (foo)
' {
' case (0) writefln("one statement for case 0"); <-- doesn't fall
through
' case (1)
' {
' writefln("case 1");
' writefln("has two statements");
' }
' case (2, 3)
' {
' writefln("case 2 or case 3");
' writefln("falls through to case 4);
' continue 4;
' }
' case (4)
' {
' writefln("case 4");
' if (foo == 2) break; // <-- break still breaks out of the switch
' writefln("not case 2");
' }
' else writefln("switch default");
' }
Still would like that better than the C syntax (and it saves a keyword!),
but, anyway: If you write the break as soon as you write the case label
and then insert the code you'll never forget the break. This works, this
way I never forgot a break in years.
-mike
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list