Hi, I'm wondering what the best way to find out if a variable equals one of two or more values is.
for example:
Code:
if (i == 2 || i == 3) {
do_something();
do_something_else();
} else {
do_nothing();
do_nothing_else();
}
or if you use an inline if:
Code:
(i == 2 || i == 3) ? do_something : do_nothing;
the problem i find with this is that i can never equal both 2 and 3 at the same time, and there's no logical XOR operator in C. so is the following way the correct one?:
Code:
switch(i) {
case 2:
case 3:
do_something();
do_something_else;
break;
default:
do_nothing();
do_nothing_else;
break;
}
or is there a better way to write this?