Updated on Kisan Patel
In javascript, the break statement is used to break the loop completely in middle.
The following script shows the use of break.
for (i = 10; i >= 0; i--) { if (i == 5) { break; } } document.write("My Lucky number is" + i);
See the Pen xGeXZZ by Kisan (@pka246) on CodePen.
The continue
statement is used to skip the current iteration and continue with the next iteration of the loop.
for (i = 10; i >= 0; i--) { if (i == 5) { x = i; continue; } document.write(i); document.write("<br/>"); } document.write("The number " + x + " is missing in above list");
See the Pen mJgBVB by Kisan (@pka246) on CodePen.