User Guide

Table Of Contents
38 Chapter 2: Elements of CFML
<cfset myArray = ArrayNew(1)>
<!--- Use ArraySet to initialize the first ten elements to 123 --->
<cfset ArraySet(myArray, 1, 10, 123)>
<cfset myArray[4] = "kumquats">
<cfset foundit = False>
<cfset i = 0>
<cfloop condition = "(NOT foundit) AND (i LT ArrayLen(myArray))">
<cfset i = i + 1>
<cfif myArray[i] IS "kumquats">
<cfset foundit = True>
</cfif>
</cfloop>
<cfoutput>
i is #i#<br>
foundit is #foundit#<br>
</cfoutput>
Note: You can get an infinite conditional loop if you do not force an end condition. In this example, the
loop is infinite if you omit the
<cfset i = i + 1> statement. To end an infinite loop, stop the
ColdFusion application server.
cfbreak
The
cfbreak tag exits the cfloop tag. You typically use it in a cfif tag to exit the loop if a
particular condition occurs. The following example shows the use of a
cfbreak tag in a query
loop:
<cfloop query="fruitOrder">
<cfif fruit IS "kumquat">
<cfoutput>You cannot order kumquats!<br></cfoutput>
<cfbreak>
</cfif>
<cfoutput>You have ordered #quantity# #fruit#.<br></cfoutput>
</cfloop>
cfabort and cfexit
The
cfabort tag stops processing of the current page at the location of the cfabort tag.
ColdFusion returns to the user or calling tag everything that was processed before the
cfabort
tag. You can optionally specify an error message to display. You can use the
cfabort tag as the
body of a
cfif tag to stop processing a page when a condition, typically an error, occurs.
The
cfexit tag controls the processing of a custom tag, and can only be used in ColdFusion
custom tags. For more information see, “Terminating tag execution” on page 253 and CFML
Reference.