1

I guess every switch algorithm can be re-written by if...else if...else algorithm, then why do we still need switch any more? Is there big differences in code efficiency?

The same question also goes to for and while loop algorithms.

Daniel
  • 2,576
  • 7
  • 37
  • 51
  • 1
    [Related](http://stackoverflow.com/questions/1028437/why-switch-case-and-not-if-else-if?rq=1) – Mike G Apr 25 '13 at 15:06
  • As you can express roughly the same with different words, you can achieve roughly the same results with different programming language constructs. It is richness of language, bith verbal and programming. – skuntsel Apr 25 '13 at 15:08
  • 1
    It's not a matter of code efficiency, but of programmer efficiency. Guess what, you could even rewrite a `for` or a `while` loop with just `if` and `goto` but do **you** really wanna do that? I certainly don't! In the end, the compiler will **always** translate it to an `if/goto` loop anyway since this is pretty much the only available construct in assembly. – syam Apr 25 '13 at 15:11
  • 1
    on the `for` vs `while` question you can read [this answer](http://stackoverflow.com/questions/2950931/for-vs-while-in-c-programming) – Mateo Torres Apr 25 '13 at 15:13

0 Answers0