About switch case statements...

Michel Fortin michel.fortin at michelf.com
Sun Nov 15 10:50:02 PST 2009


On 2009-11-15 12:54:02 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> Walter's answer to that has put me to silence for good. "But I use 
> fall-through all the time!" I then knew the feature will never make it.

Hum two suggestions. Sometime I want fall-through when I write a 
switch, but I always make it clear that it isn't a bug by writing the 
intent in a short comment:

	switch (c) {
		case 1:
			blah();
			break;
		case 2:
			blah();
			// fallthrough
		case 3:
			blah();
			break;
	}

That way I can always tell when I read again the code wether this was 
intentional or not. It wouldn't hurt at all if that "fallthrough" 
comment became a keyword:

	switch (c) {
		case 1:
			blah();
			break;
		case 2:
			blah();
			fallthrough;
		case 3:
			blah();
			break;
	}

Now the intent is clear even for the compiler.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list