JavaScript's 'continue' Statement: A Friendly Guide to Skipping Steps

Tired of cluttered loops? Learn how the JavaScript 'continue' statement acts like a 'skip' button, making your code cleaner, more efficient, and easier to read

JavaScript's 'continue' Statement: A Friendly Guide to Skipping Steps
JavaScript's continue Statement: Your Code's "Skip This One" Button
Let's be honest. When you're deep in a JavaScript loop, sometimes you run into things you'd rather just... skip.
Maybe you're processing a list of users and one hasn't verified their email yet. Or you're looping through numbers and need to ignore all the even ones. Your first instinct might be to wrap your entire logic in a big, bulky if
statement.
It works, but it leads to nested code that can look like a confusing set of Russian dolls. What if I told you there was a gentler, more elegant way to say "not this one, next please!"?
That’s where our friend continue
comes in.
What Does continue
Actually Do?
In plain English, the continue
statement tells a loop to immediately stop what it's doing on the current iteration and jump straight to the next one.
It's the digital equivalent of a bouncer at an exclusive club. The loop is the line of people. The if
condition is the guest list. If the person (item
) doesn't meet the criteria (condition
), the bouncer (continue
) says "Not tonight," and that person is skipped. The bouncer then immediately moves on to the next person in line.
The loop itself doesn't break or end; it just gracefully moves on.
Let's See It in Action: A Real-World Example
Imagine we have an array of tasks for our day.
javascript
const dailyTasks = [
{ task: 'Write blog post', completed: true },
{ task: 'Fix website bug', completed: false },
{ task: 'Reply to emails', completed: true },
{ task: 'Team meeting', completed: false },
{ task: 'Plan next week', completed: true },
];
We only want to log the tasks that are done so we can feel a sense of accomplishment. Here's how we might do it with a clunky if
statement:
javascript
// The "Without Continue" way – a bit nested
for (let task of dailyTasks) {
if (task.completed) {
console.log(`✅ Done: ${task.task}`);
}
}
It's not terrible, but let's use continue
to flip the script. We'll instead look for what we don't want and skip it.
javascript
// The "With Continue" way – flat and clear
for (let task of dailyTasks) {
if (!task.completed) continue; // Skip incomplete tasks
console.log(`✅ Done: ${task.task}`);
}
See what happened there? The moment we find an incomplete task, we hit continue
and the loop jumps ahead. The console.log
only runs for the items we didn't skip.
This creates a "safety net" at the top of the loop. Any item that fails our check gets tossed out early, keeping the rest of our code block clean and focused on the "happy path."