Aaron Aaron - 3 months ago 13
C++ Question

Switch statement of ranges

Is there a way to write a switch statement in c++ where you deal with ranges.
case 0-10 do a,
case 20-40 do b,
case 40-80 do c,
etc.
I can write it out using a bunch of if else if statements but wondering if there is a more efficient way.

Answer

I can write it out using a bunch of if else if statements but wondering if there is a more efficient way.

No. There's not a more efficient way. Not to mention that the switch statement is really not supposed to be used for ranges.