<cfbreak>

edit

Used to break out of a <cfloop> or <cfwhile>

This tag must stand alone — a body/content and closing tag are not allowed.

This tag is also supported within <cfscript>

<cfbreak #string label#>
Attribute Description
label
string, optional
edit

used to address a specific loop instead of the nearest one.

Usage Notes

edit

<cfswitch>/<cfcase> does not fall through — once a case body finishes, the switch exits. There is no need (and no way) for <cfbreak> to "break the switch."

If you place <cfbreak> inside a <cfcase> that sits inside a <cfloop> or <cfwhile>, the break hoists past the implicit case-end and terminates the enclosing loop:

<cfloop from="1" to="3" index="i">
    <cfswitch expression="#i#">
        <cfcase value="2">
            <cfoutput>hit two </cfoutput>
            <cfbreak>
        </cfcase>
        <cfdefaultcase>
            <cfoutput>i=#i# </cfoutput>
        </cfdefaultcase>
    </cfswitch>
</cfloop>
<!-- i=1 hit two -->

The loop never reaches i=3 because <cfbreak> exits the loop, not the switch.

This differs from script break;, which follows C-style semantics — script case blocks fall through by default and break; exits the switch only, leaving the surrounding loop running.

Construct Case fall-through What break exits
<cfswitch> / <cfcase> no (implicit case-end) the enclosing <cfloop> / <cfwhile>
switch / case (script) yes the switch

Mixing the two mental models is the usual footgun: a <cfbreak> added defensively inside a <cfcase> will silently cut an outer loop short, with no error or warning.

Examples

edit
// breaking out using a label
x = 0;
WhileLabel: while (x < 10){
    writeOutput("x is #x#<br>");
    switch (x){
        case 1:
            break;
        case 3:
            break WhileLabel;
    }
    x++;
    writeOutput("end of loop<br>");
}
writeOutput("After loop, x is #x#<br>");

See also