Suggestion: new switch statement
mike
vertex at gmx.at
Mon Aug 21 06:18:00 PDT 2006
Hi!
If I may comment on that - I think that fits perfectly into the syntax.
Think of that:
' class foo
' {
' // you can write public in 3 different ways
' public int x;
' public
' {
' int y;
' }
' public:
' int z;
' }
Why not something similar with switch?
' switch (i)
' {
' // you could write case in 3 different ways too
' case 1 writefln("case 1");
' case 2
' {
' writefln("case 2");
' }
' case 3:
' writefln("case 3");
' break;
' }
That would be really nice of one has lots of 1-line switch cases. I'd like
that very much.
-Mike
Am 21.08.2006, 13:05 Uhr, schrieb Kristian <kjkilpi at gmail.com>:
> 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...!!
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list