Improvement to switch-case statement

Jarrett Billingsley jarrett.billingsley at
Wed Dec 31 14:41:11 PST 2008

On Wed, Dec 31, 2008 at 5:16 PM, Mike James <foo at> wrote:
> Just an idea that could improve Ds switch-case statement - add an elipsys as in object Pascal to allow case ranges.
> switch (var) {
>    case 1:
>        \\ do something
>        break;
>    case 2..10:
>        \\ do something else
>        break;
> }
> What do people think?

It's such a common need, and such a simple thing to implement, that
I'm absolutely shocked that more languages _haven't_ adopted it.  It's
annoying when you're writing some kind of string parser and have to
put all sorts of stuff in the 'default' that could easily be handled
by cases like this.

In fact, I'll put it in MiniD right now.  Geez.

More information about the Digitalmars-d mailing list