-
Break statement
-
Use the break statement to terminate the loop.
-
Continue statements
-
use the Continue statement to terminate the current loop, and then proceed from the next value.
JavaScript Break and Continue statements
There are two special types of statements that can be used inside loops: Break and continue.
Break
The break command terminates the run of the loop and then resumes execution of the code after the loop (if there is code after the loop).
Instance:
{break} document.write ("The number is" + i) document.write ("<br/>")}</script></body>
Results:The number is 0The number was 1The number is 2
Continue
The continue command terminates the current loop and then continues to run from the next value.
Instance:{continue} document.write ("The number is" + i) document.write ("<br/>")}</script></body>
Results:The number is 0The number are 1The number is 2The number are 4The number is 5The number are 6The number is 7The number is 8Th E number is 9The number is 10
The break and continue of JavaScript