Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Use the Continue Statement in TypeScript Loops

Use continue in a TypeScript loop to skip the rest of the current iteration. Learn how it behaves in for, while, for...of, for...in and nested loops.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Place continue; inside a loop after the condition that identifies an item to skip. It skips the rest of the current loop-body pass and proceeds to the next iteration. In a traditional for loop, the update expression still runs before the loop checks its condition again.

Skip an iteration with continue

Use an if guard to make the skip condition clear, then put continue; inside that branch:

As an Amazon Associate I earn from qualifying purchases.

const values: number[] = [1, 2, 3, 4, 5];

for (let i = 0; i < values.length; i++) {
  if (values[i] % 2 === 0) {
    continue; // Skip even values
  }

  console.log(values[i]); // 1, 3, 5
}

When the value is even, the loop skips console.log. For odd values, execution reaches it normally. TypeScript adds a type system to JavaScript; continue follows JavaScript’s control-flow behavior, rather than being a TypeScript-only feature (MDN: continue).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens in each loop type?

Traditional for

After continue, JavaScript runs the loop’s update expression, such as i++, then checks the loop condition. The counter therefore still advances in the example above.

while and do...while

In a while loop, control returns to the condition. In a do...while loop, it proceeds to the condition check at the end of the body. If a while condition depends on state that the body changes, ensure the skip path still changes that state; otherwise, the condition may remain true indefinitely.

for...of and for...in

With for...of, continue skips processing the current value and proceeds with the next value from the iterable. With for...in, it skips the current property key. For arrays, for...in generally gives index-like keys, not element values. Choose the loop form that matches what you need to process: the TypeScript Handbook explains that for...of visits iterable values, while for...in inspects object properties (TypeScript Handbook: Iterators and Generators).

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Choose between continue and break

  • Use continue to skip the rest of the current iteration and keep looping.
  • Use break to exit the loop entirely.

A continue must apply to a loop. A switch statement by itself is not a loop, but a continue in a switch nested inside a loop continues that enclosing loop. See MDN’s continue reference for the statement’s control-flow rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use a label to continue an outer loop

An unlabelled continue applies to the innermost enclosing loop. To skip the rest of an outer loop’s current iteration from inside a nested loop, label the outer loop and use that label with continue:

outer: for (const row of rows) {
  for (const cell of row) {
    if (cell === null) {
      continue outer;
    }
    process(cell);
  }
}

If a cell is null, this skips the remaining inner-loop work and starts the next outer iteration. Without outer, continue; would move to the next cell in the current row. Labels can make control flow harder to follow, so consider whether a clearer condition or a helper function would suit deeply nested logic better.

Common errors to avoid

  • Expecting a for loop to skip its update: The update expression runs after continue and before the next condition check.
  • Forgetting progress in a while loop: Make sure the skip path changes state when that state controls whether the loop continues.
  • Using for...in to process array values: It enumerates keys; use for...of when you need values.
  • Using an unlabelled continue in nested loops to target the outer loop: It affects only the innermost loop. Use a label when the outer-loop jump is intentional.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.