| Contents > CFML Reference > ColdFusion Tags > cfbreak |
|
|
|
|
||
Used within a cfloop tag. Breaks out of a loop.
<cfbreak>
cfabort, cfexecute, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry
<!--- 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.number")>
<cfif Not IsNumeric(form.number)>
<cfabort>
</cfif>
</cfif>
<cfquery name="GetCourses" datasource="cfsnippets">
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="index.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>
|
|
||
| Contents > CFML Reference > ColdFusion Tags > cfbreak |
|
|
ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-pa7.htm
Comments
Steve said on Feb 17, 2004 at 8:14 AM :