Used within a cfloop tag. Breaks out of a loop.
<cfbreak>
cfabort, cfexecute, cfif, cflocation, cfloop, cfthrow, cftry; cfloop and cfbreak in Elements of CFML in ColdFusion MX Developer's Guide
<!--- This shows the use of cfbreak to exit a loop when a condition is met.--->
<!--- Select courses; use cfloop to find a condition; then break the loop. --->
<!--- Check that number is numeric. --->
<cfif IsDefined("form.course_number")>
<cfif Not IsNumeric(form.course_number)>
<cfabort>
</cfif>
</cfif>
<cfquery name="GetCourses" datasource="cfdocexamples">
SELECT *
FROM Courses
ORDER by course_number
</cfquery>
<p> This example uses CFLOOP to cycle through a query to find a value.
(In our example, a list of values corresponding to courses in the Snippets
datasource). When the conditions of the query are met, CFBREAK stops the loop.
<p> Please enter a Course Number, and hit the "submit" button:
<form action="cfbreak.cfm" method="POST">
<select name="courseNum">
<cfoutput query="GetCourses">
<option value="#course_number#">#course_number#
</cfoutput>
</select>
<input type="Submit" name="" value="Search on my Number">
</form>
<!--- If the courseNum variable is not defined,
don't loop through the query.--->
<cfif IsDefined ("form.courseNum") IS "True">
<!--- Loop through query until value found, then use CFBREAK to exit query.--->
<cfloop query="GetCourses">
<cfif GetCourses.course_number IS form.courseNum>
<cfoutput>
<h4>Your Desired Course was found:</h4>
<pre>#course_number# #descript#</pre>
</cfoutput>
<cfbreak>
<cfelse>
<br> Searching...
</cfif>
</cfloop>
</cfif>
ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting
Version 7
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000221.htm
Comments
jrunrandy said on Feb 9, 2005 at 7:02 AM :