Used to break out of a CFLOOP. See Breaking out of a loop, later in this chapter, for more information.
<CFBREAK>
<!--- This example shows the use of CFBREAK to exit
a loop when a condition is met --->
<!--- select a list of courses and use CFLOOP to find a condition
and then break the loop --->
<CFQUERY NAME="GetProducts" DATASOURCE="CFExpress">
SELECT *
FROM Products
ORDER by Product_Name
</CFQUERY>
<HTML>
<HEAD>
<TITLE>
CFBREAK Example
</TITLE>
</HEAD>
<BODY bgcolor=silver>
<H1>CFBREAK Example</H1>
<P>This example uses CFLOOP to cycle through a query to find a desired
value. (In our example, a list of values corresponding to products in the
CFExpress datasource).
When the conditions of the query are met, CFBREAK stops the loop.
...
<!--- loop through the query until desired value is found,
then use CFBREAK to exit the query --->
<CFIF IsDefined("form.a_prod")>
<CFLOOP QUERY="GetProducts">
<CFIF product_ID is form.a_prod>
<H4>Your Desired product was found:</H4>
<PRE><CFOUTPUT>#product_name# #product_description#</CFOUTPUT></
PRE>
<CFBREAK>
<CFELSE>
<BR>Searching...
</CFIF>
</CFLOOP>
</CFIF>
<FORM action="cfbreak.cfm" method="post">
<select name="a_prod" >
<option value="1">ColdFusion</option>
<option value="2">HomeSite</option>
<option value="3">JRUN</option>
</select>
<INPUT type="Submit" Value="Select an Allaire Product">
</form>
</BODY>
</HTML>