Switch The "switch ()"
from
JoeUser Forums
Why does Java and other popular programming languages like C, C++ "Switch" statements have a fall through behaviour by default,
the most common or popular use of a switch statment is when we just want to choose a paticular option based on the value passed to switch statement and then get out of it, the fallthrough behavior is not what is needed most of the time ( atleast thats what my programming experience says..), you end up putting "break;" statements just to avoid this fall through most of times,
why was the switch statement not designed the other way round, put a statement in "case 'x':" which allows you to fallthrough if you need it, the default behavior will be just to "break" out of switch after a matching case is found,
will it not help and save lots of LOC worldwide...
the most common or popular use of a switch statment is when we just want to choose a paticular option based on the value passed to switch statement and then get out of it, the fallthrough behavior is not what is needed most of the time ( atleast thats what my programming experience says..), you end up putting "break;" statements just to avoid this fall through most of times,
why was the switch statement not designed the other way round, put a statement in "case 'x':" which allows you to fallthrough if you need it, the default behavior will be just to "break" out of switch after a matching case is found,
will it not help and save lots of LOC worldwide...