This is a js tutorial-using JavaScriptBreak and Continue. There are two statements that can be used in a loop: break and continue. JavaScriptbreak and continue statements have two special types of statements available in the loop: break and continue. The Breakbreak command can terminate the running of the loop, and then run
This is a js tutorial-JavaScript Break and Continue. There are two types of statements that can be used in loops: break and continue.
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:
Var I = 0
For (I = 0; I <= 10; I ++)
{
If (I = 3) {break} document. write ("The number is" + I)
Document. write (" ")
}
Script
Result:
The number is 0
The number is 1
The number is 2
Continue
The continue command terminates the current loop and continues running from the next value.
Instance:
Var I = 0
For (I = 0; I <= 10; I ++)
{
If (I = 3) {continue} document. write ("The number is" + I)
Document. write (" ")
}
Script
Result:
The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10