Course contentsShow
← JavaScript
Lesson 332 of 2,7239. Control FlowFree lesson

Continuing Outer Loops with Labeled Continue

Applying labeled continue to skip iterations in outer loops rather than just the innermost loop.

Continuing Outer Loops with Labeled Continue

You'll learn how to skip iterations in an outer loop using labeled continue statements.

You've seen how labels can help you break out of nested loops. They're equally useful with continue, letting you skip the current iteration of an outer loop rather than just the innermost one.

How It Works

Without a label, continue always affects the loop it's directly inside. But sometimes you need to jump back to the next iteration of an enclosing loop—skipping all remaining code in both the inner and outer loop bodies for that cycle.

By combining a label with continue, you specify exactly which loop's iteration should restart.

The Pattern

outerLoop: for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 3; j++) {
    if (i === 1 && j === 1) {
      continue outerLoop; // Skip rest of outer iteration when i=1, j=1
    }
    console.log(`i=${i}, j=${j}`);
  }
  console.log(`Finished inner loop for i=${i}`);
}

Output:

i=0, j=0
i=0, j=1
i=0, j=2
Finished inner loop for i=0
i=1, j=0
i=2, j=0
i=2, j=1
i=2, j=2
Finished inner loop for i=2

Notice when i=1 and j=1, the continue outerLoop skips both the rest of the inner loop and the "Finished" message, jumping straight to i=2.

When You Need This

Labeled continue shines when processing multi-dimensional data where certain outer-level conditions invalidate the entire row, batch, or group—making it pointless to check remaining inner items.

Key Takeaway: Labeled continue lets you skip to the next iteration of an outer loop, not just the current one, giving you precise control over nested loop flow.