If Statement vs. Switch Statement
If Statement vs. Switch Statement
If Statement
![ifstatement.png](https://steemitimages.com/640x0/https://steemitimages.com/DQmWtdqDqpRuHEqn5nfMBTnHkMdsqRrxZB9KSVeFPyFr33a/ifstatement.png)
Switch Statement
![switch.png](https://steemitimages.com/DQmYKsGbhojU4BSDk8rZrJiriiwbAm3UWrZdgHmojYdLzvR/switch.png)
In my experience switch statement is faster than if statement. It always depends on the situation whether you will use if statement or switch statement. I use switch statement when I am trying to switch the value of a single variable. However switch statement is not always faster than the if statement as some of the compilers are able to optimize performance by constructing jump tables. In this way each condition doesn't have to be tested in if/else statements.