>>11237593>>11237634The compiler converts switch and if statements to low-level code which has no such thing as if statements or switch statements.
When a compiler comes across a switch statement, one way it can translate this is by using a jump table. As any programmer knows, in a switch statement, you "switch" on a single expression and have many "cases," each of which specifies specific code to run if the expression matches the value specified by the case. Since the value of the expression being switched on is effectively a number, you can create an array with one element for each value the switch statement needs to handle. Each element of the array points to an address to jump where the code that should be executed for that case is stored. The array is what a jump table is.
The reason compilers like to use jump tables is because it takes fewer steps to go from having a value you want to switch on, to running the code specific to that value. In a typical if statement setup with many else if clauses, when the code runs, the computer must run through the if statement sequentially. If you have a hundred clauses and the last one is the one that will be executed, the computer will have to check one hundred conditions before it gets to the code for the correct condition. If the if statement could be converted to a switch statement (which is not always the case), then the computer would not have to go through any of that hassle.
For large switch statements, jump tables are generally preferred, but for smaller ones, it is usually faster to do it the same way as if statements. The compiler makes this decision for you.