Can (switch) statement do the same as double(if.....else) stament and when can I use each one of them? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Can (switch) statement do the same as double(if.....else) stament and when can I use each one of them?

16th May 2020, 12:16 PM
Moaaz Osman
Moaaz Osman - avatar
3 Answers
+ 4
Moaaz Osman Yes do the same In multiple if else statement check each and every condition so program will take so much execution time so to avoid this situation we use switch statement because in switch statement once the condition will satisfy then program will terminate there that's why we use break in switch.
16th May 2020, 12:25 PM
A͢J
A͢J - avatar
+ 2
No switch is applicable to discrete conditions only. if else is applicable to both discrete and continuous conditions.
16th May 2020, 12:27 PM
Gordon
Gordon - avatar
0
We can check many conditions in single if statement but in switch statement, we must have exact answer to check.
16th May 2020, 12:41 PM
Manish
Manish - avatar