• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about switches  RSS feed

 
Tom Hong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had two questions regarding switches.



Question #1: will the switch always go through every single case that is 'i' and larger if I don't include break statements?

Question #2: why does the default show up even though at least one of the cases match 'i'? Is it for same/similar reason(s) as question #1?

Thanks in advance.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you find when you looked in a book, or even googled it? or wrote a simple test program and ran it?

We love answering questions, but we do expect you to do a LITTLE work on your own...If you find something that doesn't make sense, we're happy to help clarify.
 
Tom Hong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried messing around with it (before I opened this thread) and found the two situations to be the case indeed. However, I just wanted to be sure that this was indeed how it worked and that I wasn't doing something wrong.

I've also tried googling it a bit. Although my googling wasn't super extensive, I couldn't find anything specific on this.
 
Terry Tucker
Greenhorn
Posts: 24
Linux Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want it to fall through, the "break" out of the switch. That is the answer to both questions.
 
Terry Tucker
Greenhorn
Posts: 24
Linux Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry Tucker wrote:If you don't want it to fall through, the "break" out of the switch. That is the answer to both questions.

"then break out of the switch"
 
Tom Hong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Thank you!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!