Possible Duplicates:
is “else if” faster than “switch() case” ?
What is the relative performance difference of if/else versus switch statement in Java?
I am just wondering if one is better (i.e. more efficient). To me the seem to be the same other than the syntax.
The compiler can create a jump table for certain types of switch statements which is more efficient than just evaluating each element like a nested set of if statements. This is dependent on the type of switch and the language you are working in, but many C compilers just this sort of thing in their code generation.
So the short is that a switch can be more efficient but it depends on your particular usage.