continue
Skips the rest of the current loop iteration and proceeds to the next one.
Syntax
continue;
continue label;
Examples
for (let i = 0; i < 5; i++) {
if (i % 2 === 0) continue;
console.log(i);
}
Output
1
3
let i = 0;
while (i < 5) {
i++;
if (i === 3) continue;
console.log(i);
}
Output
1
2
4
5
outer:
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (j === 1) continue outer;
console.log(i, j);
}
}
Output
0 0
1 0
2 0
Notes
- In a `for` loop the update expression still runs after `continue`.
- A labeled `continue` continues the next iteration of the labeled loop.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |