Document directory
- Break
- Instance:
- Result:
- Continue
- Instance:
- Result:
There are two statements that can be used in a loop: Break and continue.
Instance
-
Break statement
-
Use the break statement to terminate the loop.
-
Continue statement
-
Use the continue statement to terminate the current loop and continue execution from the next value.
Javascript break and continue statements
There are two special statements available in the loop: Break and continue.
Break
The break command can terminate the running of the loop and then continue executing 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>Result:
The number is 0The number is 1The number is 2
Continue
The continue command terminates the current loop and continues running from the next value.
Instance:
{continue}document.write("The number is " + i)document.write("<br />")}</script></body>Result:
The number is 0The number is 1The number is 2The number is 4The number is 5The number is 6The number is 7The number is 8The number is 9The number is 10