I was just wondering if the switch statement usually generates more
efficient code than an if/else. If not, then what is the main
benefit
of the switch statement?
As Stroustrup has written in section 6.3.2 of 3rd the switch statement
is equivalent to if/else statement except that:
1. Sometimes it is more readable that equivalent if/else, because
testing a value against some constants are explicit.
2. It can also lead to a better code generation. I think it is
implementation dependent.
The C++ Standard Document doesn't mention switch statements are more
efficient than if/else statement.
I think you use both statements from programming styles point of view.
Regards,
S. Amrollahi