🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEjavascript

javascript Documentation

LOADING ENGINE...

continue Statement

AI & DATA SCIENCE // continue

continue skips the rest of the current loop iteration and moves to the next one.

Syntax

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

Deep Dive Course

**continue** jumps to the next iteration of the loop, skipping the remaining code in the current iteration. Unlike **break**, it does not exit the loop. It's useful for filtering items inside a loop without deeply nesting if statements.

1Understanding continue Statement

continue jumps to the next iteration of the loop, skipping the remaining code in the current iteration. Unlike break, it does not exit the loop. It's useful for filtering items inside a loop without deeply nesting if statements.

💡

continue reduces nesting by inverting conditions: instead of 'if (valid) { doWork() }', write 'if (!valid) continue; doWork()'.

editor.html
// Process only positive numbers
const nums = [1, -2, 3, -4, 5, -6];
const positives = [];

for (const n of nums) {
  if (n <= 0) continue; // skip negatives
  positives.push(n * 2); // only runs for positives
}
console.log(positives);
localhost:3000

2Practical Example

Here is a real-world application of continue Statement showing how it is used in production JavaScript code.

editor.html
// Skip processing errors in a batch
const records = [
  { id: 1, valid: true  },
  { id: 2, valid: false },
  { id: 3, valid: true  },
];

for (const rec of records) {
  if (!rec.valid) { console.log(`Skipping ${rec.id}`); continue; }
  console.log(`Processing ${rec.id}`);
}
localhost:3000

3Best Practices

Follow these guidelines when working with continue Statement:

1. Use continue to skip invalid items early in the loop

2. Combine with labeled statements for nested loops

3. Consider filter() as a cleaner alternative for arrays

⚠️

Tip: continue reduces nesting by inverting conditions: instead of 'if (valid) { doWork() }', write 'if (!valid) continue; doWork()'.

editor.html
// Process only positive numbers
const nums = [1, -2, 3, -4, 5, -6];
const positives = [];

for (const n of nums) {
  if (n <= 0) continue; // skip negatives
  positives.push(n * 2); // only runs for positives
}
console.log(positives);
localhost:3000

Examples

Example 01Basic Usage
// Process only positive numbers
const nums = [1, -2, 3, -4, 5, -6];
const positives = [];

for (const n of nums) {
  if (n <= 0) continue; // skip negatives
  positives.push(n * 2); // only runs for positives
}
console.log(positives);
Example 02Advanced Example
// Skip processing errors in a batch
const records = [
  { id: 1, valid: true  },
  { id: 2, valid: false },
  { id: 3, valid: true  },
];

for (const rec of records) {
  if (!rec.valid) { console.log(`Skipping ${rec.id}`); continue; }
  console.log(`Processing ${rec.id}`);
}

Best Practices

  • Use continue to skip invalid items early in the loop
  • Combine with labeled statements for nested loops
  • Consider filter() as a cleaner alternative for arrays

Interview Question

How is continue different from break?

Hint: One skips; the other stops.

break exits the loop entirely — no more iterations. continue skips only the CURRENT iteration and proceeds to the next one. Use break when you're done with the loop; use continue when you want to skip certain items but keep looping.

Exercises

MediumPractice using continue Statement in a real scenario.
View Solution
// Process only positive numbers
const nums = [1, -2, 3, -4, 5, -6];
const positives = [];

for (const n of nums) {
  if (n <= 0) continue; // skip negatives
  positives.push(n * 2); // only runs for positives
}
console.log(positives);

Frequently Asked Questions

How is continue different from break?

break exits the loop entirely — no more iterations. continue skips only the CURRENT iteration and proceeds to the next one. Use break when you're done with the loop; use continue when you want to skip certain items but keep looping.

Related Functions

breakloopsforwhile