• Post Reply Bookmark Topic Watch Topic
  • New Topic

One simple enum question (from HF Java)  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I have read almost the entire HF Java book. While checking the appendix, I saw something that I can't figure out. This is what they have:



//later down the page



They say the output is "go deep Cassidy!" Why? ifName = Members.PHIL and not Members.BOBBY (or both)
Thanks.
 
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A switch will use the first case it matches, and then every case after that one, unless it encounters a break command.

So this code would jump to PHIL, output "go deep ", then continue on to BOBBY and output "cassidy!".
If you wanted it to print only the line belonging to the case, you would have to put a "break;" after each case's commands.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes exactly Jan
this concept is called "fall threw inside switch" ,that is if any case lable is matched, from that statement onwards all the remaining statements will be executed until some "break" or end of switch.
 
Joe Hernandez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh I see, so that was the use for break way before in the book. Great thanks a lot guys!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!