Google Search

Friday, November 13, 2015

Keeping in mind the efficiency, which one between if-else and switch is more efficient?

Between if-else chain and switch statements, as far as efficiency is concerned it is hard to say that which one is more effect because both of them posses hardly any difference in terms of efficiency. 
Switch can be converted into if else chain internally by the compiler.
Switch statements are compact way of writing a jump table whereas if-else is a long way of writing conditions.
Between if-else and switch statements, switch cases are preferred to be used in the programming as it is a compact and cleaner way of writing conditions in the program.

No comments:

Post a Comment