0

Why switch case better then if else?

Quote :"You can achieve the same result with multiple if...else statements, but the switch statement is more effective in such situations." Why is it more effective??

9th Jun 2017, 3:49 PM
Elias Fzada
Elias Fzada - avatar
3 Respuestas
+ 6
switch statement is faster to execute than the if-else-if ladder. This is due to the compiler's ability to optimise the switch statement. In the case of the if-else-if ladder, the code must process each if statement in the order determined by the programmer. However, because each case within a switch statement does not rely on earlier cases, the compiler is able to re-order the testing in such a way as to provide the fastest execution.
9th Jun 2017, 3:53 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
Perfect thank you!!!
9th Jun 2017, 3:54 PM
Elias Fzada
Elias Fzada - avatar
0
welcome ;)
9th Jun 2017, 3:56 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar