+ 1

What the difference between (else if )and (switch_case)!?

l think they do the same work!

27th Jan 2018, 7:52 PM
Afnan Eljak
2 Answers
+ 1
Frankly, you're quite right! The reason that there's an option for a switch statement is because it allows for an easier way to test the value of a certain variable, which can be a little more limiting compared to the else-if statements.
27th Jan 2018, 8:20 PM
Faisal
Faisal - avatar
+ 1
similar but not same, see e.g. Duff's device. And switch is not more limiting, you have normally more freedom with switch, because its more or less only a pack of goto's.
27th Jan 2018, 11:08 PM
---
--- - avatar