JavaScript Continue Statement: Skipping Iterations

The continue statement skips the rest of the current loop iteration and jumps to the next one. Learn how to cleanly filter out items without deeply nested if blocks.

5 min read

The continue statement tells JavaScript to skip the rest of the current loop iteration and jump straight to the next one. The loop does not stop -- it just ignores whatever comes after continue in that particular pass and moves on.

It works in for, while, and do while loops. It does not work in forEach or other array methods.

Basic continue in a for Loop

The simplest use of continue is filtering out values you do not want to process:

javascriptjavascript
for (let i = 0; i < 6; i++) {
  if (i % 2 !== 0) {
    continue;
  }
  console.log(i);
}

Each odd value triggers continue and skips straight past the print statement, while every even value falls through and gets logged. Output:

texttext
0
2
4

When i is odd, continue runs and the print statement is skipped. The loop still increments i via the update expression, checks the condition, and continues to the next even number. Only odd values are filtered out.

Continue statement flow in a for loop

In a for loop, continue does NOT skip the update expression. The counter always increments, which prevents the loop from getting stuck on the same iteration. This is different from while loops, where you must be more careful.

continue in a while Loop

In a while loop, continue jumps to the condition check. You must make sure the variable that controls the condition is updated before the continue:

javascriptjavascript
let i = 0;
 
while (i < 5) {
  i++;
  if (i === 3) {
    continue;
  }
  console.log(i);
}

Because i increments before the check, continue only ever skips the print for the value 3, and the loop keeps advancing normally afterward. Output:

texttext
1
2
4
5

Notice the increment comes before the continue check. If it were after, the loop would get stuck at i equal to 3 forever because i would never increment past 3. In a for loop the update runs automatically; in a while loop you manage it yourself.

Using continue as a Guard Clause

Continue lets you write flat, readable loop bodies by bailing out early for uninteresting cases:

javascriptjavascript
const students = [
  { name: "Alice", score: 92 },
  { name: "Bob", score: 45 },
  { name: "Carol", score: 78 },
];
 
for (const student of students) {
  if (student.score < 50) continue;
  if (student.name === "Bob") continue;
  console.log(`${student.name}: pass`);
}

Each continue acts as an early exit for one filter condition, so only students who clear both checks reach the final print statement. Output:

texttext
Alice: pass
Carol: pass

Without continue, the exact same filtering logic would require nested if blocks instead of flat, early-exit checks, and it gets harder to read as more conditions are added:

javascriptjavascript
for (const student of students) {
  if (student.score >= 50) {
    if (student.name !== "Bob") {
      console.log(`${student.name}: pass`);
    }
  }
}

The continue version is easier to scan because each filter condition stands on its own line. You read down the list: skip low scores, skip Bob, process the rest.

Labeled continue for Nested Loops

A plain continue only affects the innermost loop. To skip to the next iteration of an outer loop from inside an inner loop, use a label:

javascriptjavascript
outer: for (let i = 1; i <= 3; i++) {
  for (let j = 1; j <= 3; j++) {
    if (j === 2) {
      continue outer;
    }
    console.log(`i=${i}, j=${j}`);
  }
}

Because the label targets the outer loop, continue outer abandons the rest of the inner loop entirely and jumps straight to the outer loop's next value. Output:

texttext
i=1, j=1
i=2, j=1
i=3, j=1

When j equals 2, continue outer skips the rest of the inner loop AND skips to the next outer iteration. The inner loop never reaches j equal to 3 for any outer iteration, because j reaching 2 always triggers the skip to the next i.

continue vs break vs return

StatementEffectLoop Continues?
continueSkip current iterationYes, next iteration runs
breakExit entire loopNo, loop stops
returnExit entire functionNo, function stops
javascriptjavascript
function processNumbers(nums) {
  for (const n of nums) {
    if (n === 0) continue;  // Skip zeros
    if (n < 0) break;       // Stop at first negative
    console.log(n);
  }
  console.log("Done with loop");
}
 
processNumbers([5, 0, 8, -3, 2]);
// Prints: 5, 8, Done with loop

Zero is skipped with continue. The negative number triggers break, stopping the loop. The function still prints "Done with loop" because break only exits the loop, not the function.

Common Mistakes

Putting continue after the code you want to run. continue must come before the logic you want to skip:

javascriptjavascript
// WRONG: the console.log always runs
for (let i = 0; i < 3; i++) {
  console.log(i);
  if (i === 1) continue; // Too late, already printed
}
 
// RIGHT: continue first
for (let i = 0; i < 3; i++) {
  if (i === 1) continue;
  console.log(i);
}

Using continue in forEach. Like break, continue is a syntax error inside forEach. Use return to skip in forEach, or switch to a for...of loop:

javascriptjavascript
// forEach: use return to skip
[1, 2, 3].forEach((n) => {
  if (n === 2) return; // Skips this callback, next item still runs
  console.log(n);
});
// Prints: 1, 3

Forgetting to update the counter before continue in a while loop. If the counter update is after continue, the loop becomes infinite:

javascriptjavascript
// DANGEROUS: infinite loop when i hits 3
let i = 0;
while (i < 5) {
  if (i === 3) continue; // Jumps back to condition, i stays 3
  console.log(i);
  i++;
}

Always place the counter update before any continue in a while or do while loop. In a for loop, the update runs automatically in the header.

For the counterpart that stops the loop entirely, see the break statement guide. For the subtle bug this pattern can cause, see the guide on avoiding infinite loops.

Rune AI

Rune AI

Key Insights

  • continue skips the rest of the current iteration and starts the next one.
  • In a for loop, continue still runs the update expression before the next check.
  • Use continue as an early guard to keep the main loop body unindented.
  • Labeled continue lets you skip to the next iteration of an outer loop.
  • continue does not work in forEach; use return instead.
RunePowered by Rune AI

Frequently Asked Questions

Does continue work in forEach?

No, for the same reason break does not. forEach is a method, not a loop statement. Use return inside forEach to skip the current iteration (equivalent to continue in a regular loop), or use a for...of loop instead.

What is the difference between continue and break?

continue skips the current iteration and moves to the next one. break exits the entire loop immediately. Use continue when you want to ignore one item. Use break when you want to stop looping completely.

Does continue skip the update step in a for loop?

No. In a for loop, continue jumps to the update expression (i++), then the condition is rechecked. The loop counter still increments, so you do not get stuck on the same iteration.

Conclusion

The continue statement keeps your loop logic flat and readable. Instead of wrapping the entire loop body in an if block, use continue to bail out of uninteresting iterations early. Combined with labeled continue for nested loops, it gives you precise control over which iterations to skip.