language agnostic - Why use the switch statment instead of if else statments? -
Switches seem so useless because they can be replaced with if-else statements, which are just a four / int / enum etc. . I can only think of a good use for a switch, and it will be to understand command line arguments.
What are some real uses for switch statements?
In my mind there are two reasons to use / vs, switch vs.:
- Compiler can be optimized for switch optimization.
- The switch description more clearly expresses the code's logic more specifically, it is the idea that you are taking a separate branch based on the value of something else, rather than the basis of more complex logic On. This is by far, more important reason for me.
Comments
Post a Comment