This article covers the code generation for if-else and switch statements.
The code generated for a switch statement varies a lot from one compiler to another. In fact, a given compiler might generate different code in different scenarios. The choice of the code to be generated depends upon the number and range spread of individual case statements.
Different cases of generation of a switch statement are:
- Case values are in a narrow range
- Case values are distributed over a wide range
- Number of Case values is large and they are distributed over a wide range