+ 4

What's wrong with this code?

Please explain why this code run operators in all cases and default? In fact switch shoud run operators only in one case or in default if there no coincidence with cases, or I don't know something about switch? https://code.sololearn.com/ci7pq1MpAOqM/?ref=app

20th Feb 2018, 6:14 PM
Nikita Onoshenko
Nikita Onoshenko - avatar
3 Answers
+ 11
you need to add a break statement between each case otherwise the code will execute from the first true condition and fall through to the other cases
20th Feb 2018, 6:16 PM
Dan Walker
Dan Walker - avatar
0
you have to add a break statement in each case.
21st Feb 2018, 9:28 AM
sarish biswas