- 1
i m not understanding how to use break
2 Answers
+ 4
you use a break in a switch after each case because else if the case is true and you didn't use a break it wil run all the cases after the case that was true.
+ 2
First of all break are not meant for switch case only.
Basically whenever you want to exit from loop (i.e for, foreach etc) put 'break' there.
In case of switch case we use break after each case so that if any case satisfy the condition we do not need to look at other cases.