I have a switch statement set up, with 2 cases (a or v). I could have just done an OR, but decided to practice with switch statements.

So far i'm using it to select what letter they type in, then launch the next part of the program depending on the letter they chose. Thing is, if I do:

case 'a':

then if they type "A" it will go to the default. self explanatory. But I want to know, can I add the uppercase A to the same case? Ive tried

case 'a' || 'A':

but that doesnt work.
I dont really want to have

case 'a':
(code here)
break;
case 'A':
(same code here)

etc, taking up lots of room.
Its most likely the simplest fix ever. I seem to ask the most stupid questions at the moment eheh..

thanks for help.

Recommended Answers

All 3 Replies

Just omit the break in the middle. Switch statements "fall through" until they reach a break;

case 'a':
case 'A': //do stuff here
break;
commented: fast help, thanks. +1

hey, thanks!
I knew it was simple.. I'm so stupid sometimes.

I'm so stupid sometimes.

Nah, it's just a little factoid about syntax, and now you know!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.