Difference between if else statement and case | SoloLearn: Learn to code for FREE!

0

Difference between if else statement and case

c++

2/25/2017 6:01:58 AM

adarsh singh

2 Answers

New Answer

0

The "if-else" clause can only handle for 2 different case conditions that you would like to evaluate. "switch-case" clause, however is the same as "if-else if- else" clause and can handle as many conditions as you specified for each case.

0

In addition to Corsair Alex's answer, you can check for ranges inside an if-statement (e.g. if(x > 0 && x < 10)) whereas in the switch-case, you want to pick some discrete values out of a greater set. This is when switch-case really shines. e.g. switch(x){ case 2: <some code>; break; case 5: <some other code>; break; default: <completely other code>; }