+ 1

Can we write a break statement inside a for loop?

2nd Dec 2018, 12:35 PM
Kuntal Parashar
2 Respuestas
+ 4
for (var a=0; a<5;a++){ if (a==4){ break;} alert(a); } //Output: 0 1 2 3 4
2nd Dec 2018, 1:45 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 3
Yes, you can. var a=2; while (a<10){ if (a==4){ break; } alert(a); } //Output: 2 3 4
2nd Dec 2018, 1:27 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar