DevLearningTools

🚧 This site is under active construction — new tools, guides, and pages are added every week.

MODULE 4 · LESSON 07

continue

Skipping the rest of the current loop iteration in ColdFusion without exiting the loop — CFScript's continue statement and the <cfcontinue> tag, including a real while-loop gotcha.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

continue skips the rest of the current pass through a loop and jumps straight to the next one — the loop keeps running, unlike break, which stops it entirely.

Use it to skip items that don't need processing, without wrapping the rest of the loop body in an if block.

Learning Objectives

After completing this lesson, you'll be able to:

  • Use continue to skip an iteration in CFScript.
  • Use <cfcontinue> to skip an iteration in tag syntax.
  • Avoid a common infinite-loop trap when using continue inside a while loop.
  • Use a label to continue a specific outer loop from a nested loop.

Basic continue

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

3 is skipped entirely — the loop doesn't stop, it just moves straight to the next pass.

The while Loop Gotcha

This one causes real infinite loops: in a while loop, continue jumps straight back to the condition check. If your counter update comes after the continue in the loop body, it never runs — and the loop never ends.

Broken — do not run
<cfscript>

i = 1;

while (i <= 5) {
    if (i == 3) {
        continue;
    }
    writeOutput(i & " ");
    i++; // never reached when i == 3 — infinite loop
}

</cfscript>
Fixed
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Update the counter before continue whenever it would otherwise be skipped — or restructure the loop so the update always happens before the check.

continue With a Labeled Outer Loop

Just like break, continue can target a specific outer loop by label — skipping straight to that outer loop's next pass, instead of just the innermost loop's.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Real-World Example: Skipping Invalid Entries

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Skipping bad entries with continue keeps the loop body focused on the valid case, instead of nesting everything inside an if.

Common Beginner Mistakes

Causing an infinite loop with continue in a while loop

If the code that updates your loop's condition comes after continue in the loop body, that update gets skipped every time continue runs — and the loop never ends. Update the condition before continue, or restructure the loop.

Using continue where break was actually needed

continue moves on to the next iteration; it doesn't stop the loop. If you're done looping entirely (like once a value is found), use break instead.

Forgetting continue only skips what's below it

Any code above the continue statement in that pass still runs — only the code after it in that iteration is skipped.

Best Practices

  • In a while loop, always double-check that your condition's variables get updated before any continue.
  • Use continue to keep loop bodies flat — skip bad input early instead of wrapping the rest of the logic in an if.
  • Prefer continue over deeply nested if/else when you're really just filtering out cases you don't care about.

Interview Questions

What does continue do?

It skips the rest of the current loop iteration and moves on to the next one, without exiting the loop.

How is continue different from break?

continue skips to the next iteration; break exits the loop entirely.

Why can continue cause an infinite loop in a while loop specifically?

Because continue jumps straight back to the condition check — if the code that updates the condition's variable comes after the continue in the loop body, it never runs.

What's the tag-syntax equivalent of continue?

<cfcontinue>, with an optional label attribute to target a specific labeled outer loop.

Summary

In this lesson, you learned how continue skips the rest of the current iteration in both CFScript and tag syntax, the specific infinite-loop trap it creates in a while loop if the condition's variable update comes after it, and how to use a label to continue a specific outer loop from a nested one.

This wraps up the Loops module — you've now covered for, while, do...while, for...in, the complete <cfloop> tag, and loop control with break and continue.

What's Next?

The next lesson pulls the whole module together — a decision guide for choosing between for, while, do...while, for...in, and the <cfloop> variants based on what you actually know before you loop.