Once you've done that...do you understand the idea of "falling through" in a switch statement? So, what happens if a case block doesn't have a break statement? Because that's what explains the output here.
Joined: May 19, 2013
Thanks for advice, i now put my code inside code tags, please can you explain to me the fall- trough and break concepts so i can understand the result
In a switch case, if the condition case does not have the break keyword then the code will simply Fall through so for example
The above code will output Ten Three Four No Match ... why so, because of the absence of a break keyword at case 10, so the code just "fell through" executing all the statements until it encountered a break keyword.
Hope this helps.
You can think of the "case <whatever>" as nothing more than labels. So when the "switch (x)" line is reached, the jvm decides what line to jump to. It then starts execution from that point, ignoring an more labels in the current switch statement. The only thing that would matter would be hitting a break statement, which says "now skip down to the first statement outside this switch block.