Skip to content
doubtly

1 answer

Best answer

As far as efficiency is concerned there would hardly be any difference, if at all. If the cases in a switch are sparsely distributed the compiler may internally use the equivalent of an if-else chain instead of a compact jump table. However, one should use switch where one can. It is definitely a cleaner way to program and certainly is not any less efficient than the if-else chain.
Doubtly · 11 Jun 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.