Grandpa's Fortran language has a computed GOTO statement
GOTO expr ... 1 ... ... 2 ... ...
based on the value of expr , the code jumps to 1, 2, etc.
Operator
The C (and Java) switch is basically a computed GOTO. We have a continuous piece of code with some shortcuts, and we move on to one of the shortcuts. If there is no break , we will execute the rest of the block.
This mechanism with a fairly low level of control contradicts the intuition of modern programmers; we would think that the switch statement selects one sentence and executes that sentence like the if-elseif-elseif-...-else .
Java inherited the semantics of C-switches because they did not want to deviate too much from C. Newer languages ββare unlikely to continue this error.
source share