Does anyone know if it’s possible to include a range in a switch statement (and if so, how)?
For example:
switch (x)
{
case 1:
//do something
break;
case 2..8:
//do something else
break;
default:
break;
}
The compiler doesn’t seem to like this kind of syntax – neither does it like:
case <= 8:
No, this isn’t possible. There are a few ways I’ve done this in the past:
Fixed coding:
In combination with an
if {}statement: