Set the variable to different value and then try.
Result
Entering the loop
2
3
4
5
Exiting the loop!
Đặt biến vào giá trị khác nhau và thử thử .
We have seen the usage of the break statement within a switch statement .
The continue statement tells the interpreter to immediately start the next iteration of the loop and jump over the remaining code block. When a continue statement is encountered, the program flow moves immediately to the test expression and if the condition is true, then it starts the next iteration, otherwise the control exits the loop.
For example
This example illustrates the use of the continue statement with a while loop. Notice how the continue statement is used to jump over the print when the index is kept in the x value to 5.
Set the variable to different value and then try.
Result
Entering the loop
2
3
4
6
7
8
9
ten
Exiting the loop!
Starting from JavaScript 1.2, a Label can be used with break and continue to control the flow more accurately. A label is simply an identifier followed by a colon (:) that applies to a command or block of code. We will see two different examples to understand how to use labels with break and continue.
Note - Interrupt lines are not allowed between the continue or break statement and its label name. Also, there should not be any other commands between a label name and a link loop.
Try these two examples to get a deeper understanding of Label.
Example 1
This example shows how to perform Label with a break statement:
Result
Entering the loop!
Outerloop: 0
Innerloop: 0
Innerloop: 1
Innerloop: 2
Innerloop: 3
Outerloop: 1
Innerloop: 0
Innerloop: 1
Innerloop: 2
Innerloop: 3
Outerloop: 2
Outerloop: 3
Innerloop: 0
Innerloop: 1
Innerloop: 2
Innerloop: 3
Outerloop: 4
Exiting the loop!
Example 2
This example shows how to perform Label with a continue statement:
Result
Entering the loop!
Outerloop: 0
Innerloop: 0
Innerloop: 1
Innerloop: 2
Outerloop: 1
Innerloop: 0
Innerloop: 1
Innerloop: 2
Outerloop: 2
Innerloop: 0
Innerloop: 1
Innerloop: 2
Exiting the loop!
According to Tutorialspoint
Previous article: For . loop in JavaScript
Next article: Function in JavaScript