0

What is "break"in switch/case?

29th Jul 2018, 12:35 AM
Emre GĂŒnay
Emre GĂŒnay - avatar
2 Answers
+ 3
It makes sure the next cases are skipped. Without break, the program would run all of the cases after a case that is true.
29th Jul 2018, 1:08 AM
Theresa
Theresa - avatar
+ 1
IT IS SIMILAR TO ELSE-IF STATEMENT. IN SWITCH STATEMENT YOU ARE PASSING A VALUE AND SEE IF ANY CASE MATCHES THAT VALUE IF YES YOU EXECUTE THAT BLOCK AND BREAK OUT FROM SWITCH STATEMENT. IF ANY CASE DOESNT MATCH WITH VALUE DEFAULT CASE IS EXECUTED WHICH IS SIMILAR TO ELSE IN ELSE-IF. I had tried to explain whole switch statement so you can get a clear idea. Hope this helps â˜șâ˜ș.
29th Jul 2018, 3:58 AM
Meet Mehta
Meet Mehta - avatar