On 06/21/2010 07:40 PM, Adam Ruppe wrote:
What's the point of a switch without implicit fallthrough? If you take
that away, it offers nothing that if/elseif doesn't. (Aside from not
retyping the switch(stuff here), which you can bring into a function
anyway, so whoop-de-doo. And I guess some performance boosts in
rearranging the cases, but can't the optimizer do that in if/else
anyway?)

int Case(in int value) { return myvar == value; }

if(Case(10)) {

} else if (Case(20)) {

} else  { /* default */ }

You can even use goto and labels to simulate goto case.


I'm quite serious here: fallthrough is the defining feature of the
switch.

Then why are people using switch and next to nobody uses fall through (provably including Walter, who thinks is using fall through "all the time")? Simple: because it's a structure expressing handling of a value against a set of values, whereas cascaded if/else is more general and therefore less structured.

The same argument could be made in favor of axing for since we already have while.


Andrei

Reply via email to