We used the break
keyword earlier to break out of a loop entirely.
It is also possible to simply continue
to the next iteration of the loop:
let i = 0;
while (i < 10) {
i++;
if (i % 2 === 0) {
continue;
}
console.log(i);
}
In this example, any time i
is an even number the loop will continue
.
The continue
statement causes the current iteration of the loop to stop. If the loop is still running, the next iteration will start.