Company Blog RSS Feed

ColdFusion CFBreak

September 13, 2011
Another pretty basic tag I'd like to bring up is the <cfbreak> tag. Short and sweet: This tag is used within a <cfloop> tag to break out of the loop. In this example, we're going to create a loop that starts with 1 and ends in 10, but breaks out of the loop once we hit 7. You can do this using the following code:

<cfloop index="i" from="1" to="10">
    <cfoutput>#i#</cfoutput><br>
    
    <cfif i eq 7>
        <cfbreak>
    </cfif>
</cfloop>


Here, the loop starts at 1 and loops until 7 is hit, then the <cfbreak> tag is called in the IF statement. This example would probably never be used in the real world, but gives you an idea of how the tag works.

Happy coding!



Add A Comment





Subscribe to this blog