Can we write an OR operator into a switch case? See description below | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we write an OR operator into a switch case? See description below

int a=2; switch (a) { case 1||2 : cout<< .... case 3||4 : cout<< ... Is sth like this possible?

25th Sep 2016, 11:33 PM
Serdar Bulut
Serdar Bulut - avatar
1 Answer
+ 1
No you can not. to achieve that result you could do case 1: case 2: cout<<...; break; case 3: case 4: cout<<...; break; whenever you don't use break; on a case, it does not terminate the switch and just moves on to the next test. that way you get the desired "or" effect.
26th Sep 2016, 1:52 AM
nick