You mean, something like this?
switch (some_var)
{ case 4 : // fall through
case 5 : // fall through
case 6 : do_something();
break;
default : do_something_else();
break;
}
It's ugly, and gets worse the larger a range you want to cover, but since switch
case
s must be constants, that's one way to do it.
Another way would be:
switch ((some_var > 3) && (some_var < 7))
{ case 0: do_something_else(); break;
default: do_something(); break;
}
But that'll only work if you have exactly one range you want to test. There are other ways if you have a set of equally-sized intervals that are spaced equally far apart, using some basic arithmetic, but we'd have to know a bit more about the specific problem(s) you're trying to solve...
Frankly, though, I think the if
construct is the better solution...