Back to JavaScript Notes
Topic #293

JavaScript continue

By the end of this lesson, you will be able to use JavaScript continue to skip the rest of the current loop iteration and move to the next one.

What it is

continue is a control-flow statement used inside loops such as for, while, do...while, for...in, and for...of. When the JavaScript engine reaches continue, it stops executing the remaining statements in the current iteration and starts the next iteration.

A useful mental model is a playlist: continue is like skipping the current song and moving to the next one. It does not stop the playlist; break does that. Related terms include iteration, loop body, labeled statement, and control flow.

Why it matters

  • It lets you filter items without wrapping the whole loop body in a large if block.
  • It can skip invalid or unwanted data early, such as empty strings, negative numbers, or missing fields.
  • It reduces nesting, making loops easier to read.
  • With a label, it can skip to the next iteration of an outer loop in nested loops.

Syntax or steps

The smallest useful pattern is:

if (skipCondition) {
  continue;
}

Place this inside a loop. If skipCondition is truthy, the rest of the loop body is skipped. If it is falsy, execution continues normally.

For nested loops, you can label an outer loop and continue it:

outer: for (const row of matrix) {
  for (const value of row) {
    if (value === 0) {
      continue outer;
    }
  }
}

This skips the rest of the current outer iteration when a zero is found.

Example

const nums = [1, 2, 3, 4, 5, 6];
let evenSum = 0;

for (const n of nums) {
  if (n % 2 !== 0) {
    continue;
  }

  evenSum += n;
}

console.log(evenSum); // 12

Part by part:

  • const nums = ... creates an array of numbers.
  • let evenSum = 0 stores the running total of even numbers.
  • for (const n of nums) visits each number one at a time.
  • if (n % 2 !== 0) checks whether the number is odd.
  • continue skips the addition when the number is odd.
  • evenSum += n runs only for even numbers.
  • console.log(evenSum) prints 12, because 2 + 4 + 6 equals 12.

Common mistakes

  • Using continue outside a loop. This causes a SyntaxError. Fix it by placing continue inside a loop body.
  • Thinking continue exits the loop. It only skips the current iteration. Use break when you want to stop the loop entirely.
  • Forgetting to update the loop variable in a while loop. If continue runs before an increment, the loop may never advance. Fix it by incrementing before continue or using a for loop.
  • Using continue inside a switch and expecting it to exit the switch. In JavaScript, continue affects the enclosing loop, not the switch. Use break to exit a switch case.

When to use it

Use continue when some items should be ignored but the loop should keep running. Use break when the loop should stop. Use return when you are inside a function and want to exit the function.

StatementEffectBest when
continueSkips the rest of the current iterationFiltering unwanted items
breakExits the loopFound what you need or cannot continue
returnExits the functionInside a function and done with the result

Practice

Guided exercise: Loop over const scores = [42, 78, 55, 31, 90]. Skip scores below 50 and log the passing scores.

const scores = [42, 78, 55, 31, 90];

for (const score of scores) {
  if (score < 50) {
    continue;
  }
  console.log(score);
}

Expected output:

78
55
90

Challenge: Given const names = [" Ada ", "", " Grace ", " "], skip empty or whitespace-only names and log the trimmed names. Hint: use name.trim() and check its length.

Quick check

Question: In a for loop, what happens after continue runs?

Answer: The rest of the loop body is skipped, the loop’s update expression runs, and the condition is checked for the next iteration.

Summary

continue is a simple way to skip unwanted loop iterations while keeping the loop alive. It is especially useful for filtering data and reducing nested if blocks. Use it when you want to move on, not stop.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JavaScript continue – FAQs

Quick answers about learning JavaScript continue in JavaScript.

This free note from Coding Now Tech Institute explains JavaScript continue in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JavaScript continue, is 100% free with no signup required.
With focused practice, most students grasp JavaScript continue in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now