Suggestion: new switch statement
Wim Vander Schelden
wim.vanderschelden+spam at gmail.com
Mon Aug 21 09:28:11 PDT 2006
On Mon, 21 Aug 2006 12:00:47 +0300, Kristian wrote:
> It would be nice if there was a new statement that acts like 'switch'
> except that 'break' will be automatically added at the end of the case
> statements. (We don't want to change the behavior of 'switch' because
> it'll break old code and confuse people familiar with C/C++.)
>
> Let call this new statement 'jump' (or something), for example:
>
> void func(int val) {
> jump(val) {
> case 1:
> doX();
> case 2, 3:
> doY();
> default:
> doZ();
> }
> }
I think the non-curly bracket version is nicer, as it shows how closely it
is linked to the switch statement, and you don't have to put all those
useless symbols in. I find it very annoying to type curly brackets with
if/else/elseif statements, and I think many azerty-users do. We have to
press altgr-9 to get one, which is a long way for fingers to stretch.
Curly brackets or not, I think this jump thing would make a great addition
to the language, and I completely agree with you on the break thing:
falling through is something that I rarely use, and I've forgotten more
than enough break; statements for one lifetime.
-Wim
More information about the Digitalmars-d
mailing list