Hi,
Silly question, but I need to ask it.
Given the following code:
The output of this is:
120
121
127
Of course what happens is that control hits the
test for 120 and prints 120. Because there is no "break" associated with that case, then flow continues with the 121 and 127 tests, exiting with the break in the 127 case.
But it is counter-intuitive that the println's associated with 121 and 127 would actually execute. It seems more logical that the makers of
Java would have decided that statements associated with non-matches would not execute. So in other words, in this example, 120 does not match 121 so it is more logical that the println("121") should
not execute.
So I'm wondering why the makers of Java would allow a switch statement to behave this way. Does anyone have any thoughts?
I hope that made sense. (Ravings of a mad man
)
Kind regards,
Steve