Continuing is a shift of control from the current statement to the potential start of the next iteration. It is achieved via a continue statement.
Here is an example of continuing conditionally, so that the body of the iteration does not execute for a specific item but the iteration still continues to progress:
const numbers = [1, 2, 3];
for (const n of numbers) {
if (n === 2) continue;
console.log(n);
}
// Logs: 1, 3
Continuing skips all of the code following continue in the current iteration and then moves onto whatever would naturally occur next.
Similar to the break statement, to the right side of the continue keyword can optionally be a label that indicates which iteration construct should be continued. If you don't supply it, then JavaScript will assume you are referring to the current iteration construct. If you have two or more iteration constructs nested within each other, then it may be necessary to use an explicit label:
objectsIteration: for (let obj in objects) {
for (let key in obj) {
if (/* some condition */) {
continue objectsIteration;
}
}
}
Since continuing is a movement of control, we want to remain cautious about how clearly we are communicating our intent. If we have several layers of loops or several continue or break statements, it can burden the reader with an unnecessary level of complexity.