case statement allows for runtime values,

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Apr 19 13:29:19 PDT 2011


Got it. Bug is reported.

Btw, is there a specific reason why non-const values are not allowed?

I mean, doesn't a switch statement like this:
switch(value)
{
    case 1:
        foo(); break;
    case 2:
        bar(); break;
    default:
        doo();
}

expand to:

if (value == 1)
    foo();
else if (value == 2)
    bar();
else
    doo();

You can compare anything in an if statement, so why is switch more limited?


More information about the Digitalmars-d-learn mailing list