QUOTE(INTERROBANG!? @ 15 Oct, 2008 - 11:36 AM)

So i have a question...
i was searching around the forum and after looking at some advice people were giving started to wonder "When is a switch statement appropriate to use"(as opposed to a loop with a if statement to check for bad user input).
the only case i can think of is a somewhat complicated menu or such in which the choices can not be easily organized into a array or some other data type.
let me know what you guys think.
-INTERROBANG!?
I would say that I would choose a switch statement over if statements when if it makes your code more readable.
It is much easier to read this
CODE
switch (expr) {
case c1:
statements // do these if expr == c1
break;
case c2:
statements // do these if expr == c2
break;
case c3:
...
case c4
...
default:
statements
}
than this
CODE
if (expr==c1) {
statements
} else if (expr==c2) {
statements
} else if (expr==c2 || expr==c3 || expr==c4) {
statements
} else {
statements
}