Who decided, and basing (and based on what concepts,) that switch construction (in many languages) has to be like it is? Why do we have to use break in each statement?
Why do we have to write something like this:
switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } (I've noticednoticed this construction in PHP and JS, butJS; there are probably many other languages that use itusing this)
If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:
switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } It is said, that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.