Improvement to switch-case statement
Michel Fortin
michel.fortin at michelf.com
Wed Dec 31 17:03:37 PST 2008
On 2008-12-31 18:22:32 -0500, "Adam D. Ruppe" <destructionator at gmail.com> said:
> This wouldn't be any less efficient than any other switch statement; writing
>
> case 2..5:
> code;
> break;
>
> could just be magically converted into
>
> case 2:
> case 3:
> case 4:
> case 5:
> code;
> break;
Except that if you want to keep consistency with array slices, 2..5
should probably not include 5 in the range, thus should be equivalent
"case 2,3,4". Unfortunatly, that's generally not what you want when
creating such cases. Imagine writting:
case 'a'..'{':
case 'A'..'[':
Concistent, yes; but not very appealing. What you want to be able to
write is this:
case 'a'..'z':
case 'A'..'Z':
But then it doesn't work as elsewhere in the language anymore.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list