I've got a problem where I want to do one of three things... if the value of x is 1-5 (inclusive) do A, if x is between 6-13 (inclusive) do B, and if x is between 14-16 do C.
I figured the switch case would be ok, although I guess I could use a plain IF / ELSE IF, however, as I coded it, I can't help but think there is a more elegant way of stating this USING the switch/case (just in case I encounter a similar need that has more then three options).
here is what I have:
switch ( x ) {
case 1:case 2:case 3:case 4:case 5:
// DO A
break;
case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:
// DO B
break;
case 14:case 15:case 16:
// DO C
break;
}
is there a way in the case to specify "between" (inclusive or exclusive)?
thanks