I have a problem when I want to do one of three things ... if the value of x is 1-5 (inclusive), then A, if x is between 6-13 (inclusive) do B, and if x is between 14-16 do C.
I realized that in the case of the switch, everything will be fine, although, I think, I could use a simple IF / ELSE IF, however, since I encoded it, I cannot help but think that there is a more elegant way to declare it. switch / case (just in case, I come across a similar need, which has more than 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 any way to specify βbetweenβ (inclusive or exclusive) in case of?
thanks
source share