If we don't use break, how it execute!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If we don't use break, how it execute!!

22nd May 2019, 2:41 PM
siri sa
siri sa - avatar
6 Answers
+ 4
All case will be executed after matched case until a break is detected.
22nd May 2019, 2:46 PM
Abhinav
+ 1
if you don't use the break keyword, it executes the next code block without checking the case. Example: x = 5; switch (x) { case 5: console.log("5"); case 6: console.log("6"); break; } //Output: 5 6
22nd May 2019, 2:45 PM
Airree
Airree - avatar
+ 1
No, it will execute no matter what x = 1; switch (x) { case 1: console.log(1); case 2: console.log(2); case 3: console.log(3); case 4: console.log(4); } //Output: 1 2 3 4
22nd May 2019, 2:57 PM
Airree
Airree - avatar
0
Airree it's not the next code. For ex if the next code block is false too. is it execute???
22nd May 2019, 2:50 PM
siri sa
siri sa - avatar
0
Yes, it will because it doesn't check the condition until it reaches a break
22nd May 2019, 2:53 PM
Airree
Airree - avatar
0
But my question said that don't use the break.
22nd May 2019, 2:55 PM
siri sa
siri sa - avatar