SKU // 27

JavaScript Continue

continue skips the rest of the current iteration and jumps straight to the next one. Where break says "stop the loop", continue says "skip this one, keep going".

// Basic Use

for (let i = 1; i <= 5; i++) {
  if (i === 3) {
    continue;
  }
  console.log(i);
}
1 2 4 5

When i is 3, continue skips the console.log. The loop then moves on to 4 as normal.

// break vs continue

// break: stops everything at 3
for (let i = 1; i <= 5; i++) {
  if (i === 3) break;
  console.log(i);
}
// prints 1, 2

// continue: skips only 3
for (let i = 1; i <= 5; i++) {
  if (i === 3) continue;
  console.log(i);
}
// prints 1, 2, 4, 5
break continue
Current passStopsStops
Remaining passesCancelledStill run
Works in switch?YesNo, loops only

// Filtering While You Loop

continue is handy for skipping items that do not qualify, keeping the main logic unindented:

const scores = [88, -1, 72, null, 95];
let total = 0;
let count = 0;

for (const s of scores) {
  if (s === null || s < 0) continue;   // skip bad data
  total += s;
  count++;
}
console.log("Average: " + (total / count).toFixed(1));
Average: 85.0

The same logic without continue would wrap the work inside an if. Both are correct; continue keeps the "skip" rule visible right at the top of the loop, like a bouncer at the door.

// Equivalent, using if instead of continue
for (const s of scores) {
  if (s !== null && s >= 0) {
    total += s;
    count++;
  }
}

// Skipping Evens

for (let i = 1; i <= 10; i++) {
  if (i % 2 === 0) continue;    // even? skip it
  console.log(i);
}
1 3 5 7 9

// continue in a while Loop

Be careful: in a while loop, continue jumps straight back to the condition. If the counter update comes after the continue, it gets skipped too:

// BUG: infinite loop when i hits 3
let i = 0;
while (i < 5) {
  if (i === 3) continue;   // jumps back before i++
  console.log(i);
  i++;
}

// FIX: update the counter first
let j = 0;
while (j < 5) {
  j++;
  if (j === 3) continue;
  console.log(j);
}
1 2 4 5 (from the fixed version)
Watch out
A for loop does not have this problem: its change step (i++) always runs after a continue. With while, you are responsible for making sure the counter still moves. Notice the fixed version also counts 1 to 5 instead of 0 to 4, because the counter now changes before the check.

// continue with Labels

Like break, continue can take a label (see JS Break for how labels work). A plain continue skips to the next pass of the innermost loop. continue labelname; skips to the next pass of the labeled loop instead:

let text = "";
loop1: for (let j = 1; j < 5; j++) {
  loop2: for (let i = 1; i < 5; i++) {
    if (i === 3) { continue loop2; }   // skip just i = 3
    text += i;
  }
}
console.log(text);
124124124124
let text = "";
loop1: for (let j = 1; j < 5; j++) {
  loop2: for (let i = 1; i < 5; i++) {
    if (i === 3) { continue loop1; }   // abandon this inner run
    text += i;
  }
}
console.log(text);
12121212

With continue loop2, only i = 3 is skipped, and 4 still gets added: "124" four times. With continue loop1, hitting 3 abandons the rest of the inner loop and jumps to the outer loop's next pass, so 4 is never reached: "12" four times.

Spot the twin
continue loop1 here gives exactly the same result as break loop2 from the Break lesson. "Skip to the outer loop's next pass" and "exit the inner loop" end up in the same place.

// Quick Check

What does this log?

for (let i = 1; i <= 6; i++) {
  if (i % 3 === 0) continue;
  console.log(i);
}
Show answer
1, 2, 4, 5. 3 and 6 are multiples of 3, so they are skipped. The loop still runs all 6 passes.

Why does this loop never end?

let n = 0;
while (n < 10) {
  if (n === 5) continue;
  n++;
}
Show answer
When n reaches 5, continue jumps back to the condition before n++ runs. n stays 5 forever. Move n++ above the if, or use a for loop.

You are adding up an array of prices and want to ignore any that are negative. Which fits best inside the loop?

  1. if (price < 0) break;
  2. if (price < 0) continue;
  3. if (price >= 0) continue;
  4. while (price < 0) continue;
Show answer
B. Skip the bad one and keep going. A would stop adding at the first negative, missing every price after it. C skips the good prices. D is an infinite loop.

// Try It

  1. Click Open Playground. Use continue to print 1 to 20, skipping every multiple of 3
  2. Loop over an array of words and skip any shorter than 4 letters (a string's .length is its number of characters)
  3. Rewrite your answer to step 2 using an if block instead of continue
  4. Open the labeled continue example with its Try it Yourself button and change continue loop2 to continue loop1. Then explain the buggy while example in your own words (don't run it: it freezes the tab)
// Video Walkthroughs
Last updated: Oct 9, 2026, 11:58 PM ET