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?
1 Antwort
+ 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.