JavaScript Notes
Learn the JavaScript continue statement with clear examples, flow diagrams, real-world analogies, common mistakes, and interview Q&A. Skip loop iterations like a pro!
The continue statement is a loop control tool in JavaScript that skips the rest of the current iteration and moves straight to the next one. Unlike break (which exits the loop entirely), continue just skips one iteration and keeps the loop running.
📝 Syntax
💡 Real World Analogy
Analogy: You're a security guard checking IDs at an entrance. For each person:
- If they have a valid ID → let them in (execute the body fully)
- If they're under 18 → skip them (continue to the next person)
- You never stop your entire shift (no break) — you just move to the next person
✅ Basic Examples
Example 1: Skip Even Numbers (Print Only Odd)
Odd number: 1 Odd number: 3 Odd number: 5 Odd number: 7 Odd number: 9
Example 2: Skip Multiples of 3
1 2 4 5 7 8 10 11 13 14
Numbers 3, 6, 9, 12, 15 were skipped!
Example 3: Continue in a While Loop
⚠️ Important: In a while loop, always update your counter BEFORE continue, or you'll create an infinite loop!1 3 5 7 9
Example 4: Filter Negative Numbers from Array
Added 10, running total: 10 Skipping negative: -3 Added 25, running total: 35 Skipping negative: -7 Added 42, running total: 77 Skipping negative: -1 Added 8, running total: 85 Added 15, running total: 100 Sum of positive numbers: 100
🔧 Continue in Different Loop Types
Continue in for...of Loop
Non-empty words: ✓ hello ✓ world ✓ javascript
Continue in for...in Loop (Skip Private Properties)
Public properties: name: Rahul age: 28 city: Delhi
Labeled Continue (Skip Outer Loop Iteration)
Just like break, continue can also be labeled to skip an iteration of an outer loop:
(1,1) (1,2) (1,3) (3,1) (3,2) (3,3)
Row 2 was completely skipped!
🆚 Continue vs Break — Side by Side
--- Using CONTINUE (skip 4) --- 1 2 3 5 6 7 --- Using BREAK (stop at 4) --- 1 2 3
❌ Common Mistakes
Mistake 1: Using continue in while loop WITHOUT updating counter first
1 2 4 5
Mistake 2: Using continue in a switch inside a loop
i = 0 i = 1 i = 3 i = 4
Mistake 3: Confusing continue with break
Last value: 9 Stopped at: 2
🧩 Practice Problems
Problem 1: Print Only Vowels from a String
let str = "Hello JavaScript";
let vowels = "aeiouAEIOU";
console.log("Vowels in the string:");
for (let char of str) {
if (!vowels.includes(char)) continue;
process.stdout.write(char + " ");
}
console.log();Vowels in the string: e o a a c i
Problem 2: Sum Only Even Numbers Between 1 and 20
Sum of even numbers (1-20): 110
Problem 3: Skip Invalid Records and Process Valid Ones
✓ Alice: 88 ⚠ Skipping invalid record ⚠ Skipping invalid record ✓ Diana: 91 ✓ Eve: 76 Processed 3 valid records Average: 85.0
🎤 Interview Questions
Q1. What does the continue statement do in JavaScript? > continue skips the remaining code in the current loop iteration and jumps to the next iteration. The loop itself does NOT stop — only the current cycle is skipped.
Q2. What is the difference between break and continue? > break exits the loop entirely — no more iterations run. continue skips only the current iteration and the loop proceeds to the next one.
Q3. Can continue be used in a switch statement? > continue cannot be used directly in a switch statement. If a switch is inside a loop, continue refers to the enclosing loop, not the switch. Using continue in a switch outside a loop causes a SyntaxError.
Q4. Why can continue cause an infinite loop in a while loop? > If the counter update (i++) is placed after continue, and continue is triggered, the counter update is skipped. The condition never changes, so the loop runs forever. Always place counter updates before continue in while loops.
Q5. What is a labeled continue and when is it used? > continue outerLabel skips the current iteration of a specifically named outer loop. It's used in nested loops when you want to skip an entire outer iteration based on a condition in the inner loop.
Q6. What is the output of this code?
Output:1,3,5— even numbers (0, 2, 4) are skipped bycontinue.
Q7. Is continue valid inside a for...of loop? > Yes! continue works in all loop types: for, while, do-while, for...of, and for...in.
🔑 Key Takeaways
| Concept | Detail |
|---|---|
| What it does | Skips the rest of current iteration, goes to next |
| Works in | for, while, do-while, for...of, for...in |
| Does NOT work in | switch standalone (only inside a loop containing switch) |
| Labeled continue | Skips a specific outer loop's iteration |
vs break | continue = skip this round; break = leave the game |
| Common use | Filtering, skipping invalid data, skipping certain values |
💡 Remember: continue = "I'm skipping this one — on to the next!" Use it to elegantly filter out unwanted values without breaking the loop.Exam Focus
Revise definitions, diagrams, examples, and short-answer points for JavaScript Continue Statement Tutorial – Skip Iterations with Examples.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this JavaScript Master Course topic.
Search Terms
javascript-complete-guide, javascript master course, javascript, complete, guide, control, flow, continue
Related JavaScript Master Course Topics