Switch: Case Range Syntax

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Wed Aug 17 10:40:40 PDT 2011


On Wed, 17 Aug 2011 17:27:43 +0000, Vijay Nayar wrote:

> D adds a very handy feature that allows you to check for a range of
> values in a single case.  Is there a particular reason that the syntax
> "case <start>:  .. case <end>:" is used instead of treating the case
> statement similarly to an array slice, e.g. "case <start> .. <end>:"?

This was discussed when the feature was introduced back in 2009.  See 
this thread for details:

http://www.digitalmars.com/d/archives/digitalmars/D/
Case_Range_Statement_.._92818.html

Personally, I think case range statements make more sense (and look 
better) when they are typed like this:

    switch (someNumber)
    {
        case 0:
        ..
        case 9:
           writeln("Less than 10");
           break;
        case 10:
        ..
        case 19:
           // and so on
    }

-Lars


More information about the Digitalmars-d mailing list