+ 1

Switch or If-Else-Else if

I understand the difference between the two coding structures but is there a definite advantage of using one structure over the other in certain situations? If so, could someone give an example/details of one/two of these situations?

13th Sep 2018, 5:44 PM
Jesse Linseman
Jesse Linseman - avatar
4 Respostas
+ 1
for smaller number of comparisons it doesn't matter what you use but for large comparisons switch is better, additionally switch improves the readability of your code and you can do some neat tricks by omitting the break statements for cases you want to execute together.
13th Sep 2018, 6:23 PM
vatsal uppal
13th Sep 2018, 7:54 PM
NimWing Yuan
NimWing Yuan - avatar
0
@NimWing Yuan The links you provide seem to be pages that are missing
14th Sep 2018, 6:31 PM
Jesse Linseman
Jesse Linseman - avatar