-
Notifications
You must be signed in to change notification settings - Fork 2
JS Continue
The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.
continue;
If the continue statement is used in a labeled statement, the syntax is as follows:
continue labelName;
In contrast to the break statement, continue does not terminate the execution of the loop entirely; instead:
- In a
while
loop, it jumps back to the condition. - In a
for
loop, it jumps to the update expression.
The following example shows a while
loop that has a continue statement that executes when the value of i is 3. Thus, n takes on the values 1, 3, 7, and 12.
var i = 0;
var n = 0;
while (i < 5) {
i++;
if (i === 3) {
continue;
}
n += i;
console.log (n);
}
🚀 Run Code
In the following example, a loop iterates from 1 through 9. The statements between continue and the end of the for
body are skipped because of the use of the continue statement together with the expression (i < 5)
.
for (var i = 1; i < 10; i++) {
if (i < 5) {
continue;
}
console.log (i);
}
🚀 Run Code
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links