Switch: Case Range Syntax
Vijay Nayar
madric at gmail.com
Wed Aug 17 11:00:28 PDT 2011
On Wed, 17 Aug 2011 17:40:40 +0000, Lars T. Kyllingstad wrote:
> 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
Thanks for the post! This kind of history is pretty fascinating and I'll
give it a good read. From what I've read so far, I'm surprised at how
heated the debate becomes :)
- Vijay
More information about the Digitalmars-d
mailing list