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>