JavaScript

This page explains how the continue statement skips the rest of the current loop iteration and moves to the next one.

Goal: skip one iteration without ending the loop, and keep the loop's state update safe.

continue

When JavaScript reaches continue inside a loop, it stops the current iteration. The loop then proceeds to its next iteration, so the loop itself does not end.

Skip one value

JavaScript

for (let number = 1; number <= 10; number += 1) {
  if (number === 5) {
    continue;
  }
  console.log(number);
}
// prints 1, 2, 3, 4, 6, 7, 8, 9, 10

When the number is 5, the code after continue is skipped. The loop update still runs, so the loop can move on to 6 and finish normally.

continue and break

When is it useful?

Use continue when invalid, empty, or irrelevant items should be ignored while the remaining items are processed in the same loop.

Related topics