One think about preparing for the certification exam. It has got me "nit-picking" everything about the
java programming language. May be I should just say, "It works that way because the inventors wanted it to work that way", but I don't. What I do is ask people why, or post to places like this. Sorry about that rant......
My latest "why" question. Why does the switch stmt skip the body of case arguments until it "matches" the switch condition and then execute code in all case bodies' until the end of the loop. See example:
char c = 1;
switch (c) {
default:
System.out.println("case default");
case 1:
System.out.println("case 1");
case 2:
System.out.println("case 2");
case 3:
System.out.println("case 3");
} // end switch
In the code above the default case is skipped, but case 1-3 is executed. What is the point of skipping until a hit, but then executing all the remaining cases? I know the break can be used, but it still bothers me.
Thanks,
Erik