ProgramGuru

continue Statement

Learn continue Statement

continue skips the rest of the current loop body and proceeds toward the next iteration.

In this lesson, you will study the rule, run a complete TypeScript example, explain its output, and test a small change.

What you’ll learn

  • Explain the main rule behind continue statement.
  • Predict the result of the complete runnable TypeScript example.
  • Recognize one common mistake and correct it.

Understand the concept

In a for loop, the update step still occurs after continue. In a while loop, ensure the state update is not accidentally skipped, or the loop can become infinite. Use continue to make a clear exceptional case easy to spot.

See the concept visually

Use the diagram to locate the checks, values or branches involved in the example.

continue Statement: illustrated flowCheck skip condition; True → continue; Otherwise print; Next iterationCheck skip conditionTrue → continueOtherwise printNext iteration
continue Statement: illustrated flow. Check skip condition; True → continue; Otherwise print; Next iteration.

Run a complete TypeScript example

Save this code as main.ts or paste it into the TypeScript Playground. The example uses fixed values so it runs without prompting for input.

TypeScript code

for (let id = 1; id <= 5; id++) {
   if (id === 3) {
     continue;
   }
   console.log(id);
 }

Verified output

1
2
4
5

How to run locally: npx tsc --strict --target es2022 --module commonjs main.ts, then node main.js. When using a project configuration, run the matching project build instead.

Trace the execution

The loop prints 1 and 2, skips the console.log when id is 3, then prints 4 and 5.

Predict the output before you run the sample. Compare each line with the source expression that produced it, and distinguish the type checker’s work from what happens in JavaScript at runtime.

Common mistakes and how to avoid them

continue does not terminate the loop. In a while loop, place necessary progress updates before paths that continue.

Debugging habit: when a change is rejected, read the exact compiler diagnostic and inspect the operand types. When it compiles but behaves unexpectedly, follow the values through the JavaScript expressions.

Practice it yourself

Change the condition to id % 2 === 0 and predict which values print.

Challenge: write down your prediction first, run the changed source, and explain any difference. Return to the verified version before continuing.

Check your understanding

What does continue do?
Choose one answer. You can try again.

Answer and explanation

Skip the remaining body for this iteration.

The loop can still proceed to later iterations.

Review the key idea

continue Statement: In a for loop, the update step still occurs after continue.

The loop can still proceed to later iterations.

Before continuing, be able to explain what is checked before execution and what actually changes at runtime in the example above.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Variable Scope →