+ 1
Does switch statement works faster than else if structure.? or both take the same time?
10 Réponses
+ 6
It depends on how big the code is and whether you want the script to check each condition because switch statements checks through each condition. While if else stops wherever it finds the condition true. And if you aren't doing some atomic level research or anything of that level I don't think that time difference would even matter
+ 3
both have different way to use and diiferent meathod according to tha condition
+ 3
it will take same time
+ 2
switch case is a better option if you want to reuse a same function that you need to compare diferent values, in other case if you want to use one time a function only when you find a exclusive value if else structure is a best option for you
+ 1
if you use if else structure or switch, both are faster. anyone is more faster than the other but switch is better because you can see more easier what do any statement
+ 1
kmmmpkoloilKokomog99
+ 1
yeah, the execution time of switch is high as compared to else if.Here the readon goes... In else if case, the entire loop had to be traversed to obtain the result, whereas inSwitch it need not save any comparison result to obtain the result. (Also matters Virtual Ram efficiency when doing a Big O notation analysis)
+ 1
switch is better as it is like the advanced form of nested else statement
+ 1
switch is better as it will work faster then nested if else statement
0
i think they're both taking the same time but swith is easier than if statement.