with switch statements, lets pretend the conditional is an integer and is 1.
lets say our switch looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
switch(opt)
{
case 1:
//... do some stuff
case 2:
//... do some more
case 3: opt++; break;
//...
case 4:
// do something else
case 5:
// do some more
break;
default:
errorCode();
}
|
in the case of 1, it will execute commands in 1 2 and 3, the condition is not read for the other cases, the commands are simply executed.
in the case of 2, it will execute commands 2 and 3.
in the case of 3, it will execute commands in 3.
in the case of 4, will execute 4 and 5.
in the case of 5, will execute 5.
in the case of something else will execute errorCode which happens to be a function that prints out an error to log and exits the program.
There's nothing wrong with using a switch statement to achieve this. Although it may seem awkward and hard to follow...