User Guide Cancel

cfbreak

 

Description

Used within a cfloop tag. Breaks out of a loop.

Category

Flow-control tags

Syntax

<cfbreak>

See also

cfabortcfcontinuecfexecutecfifcflocationcfloopcfthrowcftrycfloop and cfbreak in the Developing ColdFusion Applications

Tag example

 

<cfloop index="i" from="1" to="10">
<cfoutput>#i#</cfoutput>
<cfif i GE 5>
<cfbreak>
</cfif>
</cfloop>
<cfloop index="i" from="1" to="10"> <cfoutput>#i#</cfoutput> <cfif i GE 5> <cfbreak> </cfif> </cfloop>
<cfloop index="i" from="1" to="10">
    <cfoutput>#i#</cfoutput>
    <cfif i GE 5>
        <cfbreak>
    </cfif>
</cfloop>

Script example

 

<cfscript>
for (i=1; i <= 10; i++){
writeOutput(i)
if (i >= 5){
break
}
}
</cfscript>
<cfscript> for (i=1; i <= 10; i++){ writeOutput(i) if (i >= 5){ break } } </cfscript>
<cfscript>
    for (i=1; i <= 10; i++){
        writeOutput(i)
            if (i >= 5){
                break
            }
    }
</cfscript>

Either version of the code above outputs:

1 2 3 4 5

Get help faster and easier

New user?