<CFBREAK> Tag - ColdFusion
>> Return to CF Tag List
The <CFBREAK> tag will break you out of a loop or a <CFCASE> block.
Execution of the ColdFusion template will continue after the loop or CFCASE block.
This tag is not to be confused with the <CFABORT> tag which actually halts running
the ColdFusion code at the point found no matter how deep its nested.
<CFBREAK> Comments from Macromedia LiveDocsLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa7.htm cfcontinue is enhancement request 52228.LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa7.htm Why isn't there a 'cfcontinue' tag?LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa7.htm We are working to improve the examples in the ColdFusion reference pages. We propose to replace the current example on this page with the the following example. If you have any comments on this example, add them to this page. <!--- 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 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="#Number#">#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.Number IS form.courseNum> <cfoutput> <h4>Your Desired Course was found:</h4> <pre>#Number# #Descript#</pre> </cfoutput> <cfbreak> <cfelse> <br> Searching... </cfif> </cfloop> </cfif>LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa7.htm This is a known issue in ColdFusion MX 6.1 (bug number 53339).LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa7.htm i just found out today that cfbreak *also* breaks out of a cfswitch statement which it didn't used to do. So if you have a cfswitch within a cfloop and call the cfbreak inside of one of the cfcases, it will keep on looping. Personally I think this was added to the language with false logic. In most other languages the break; statement is associated with cases. i.e. in c++ it's like this: switch (expr) { case c1: statements // do these if expr == c1 break; case c2: statements // do these if expr == c2 break; } Where the break; separates the various case statements. but in cfml, we already have a </cfcase> <cfswitch expression="#expr#"> <cfcase value="c1"> statements // do these if expr == c1 </cfcase> <cfcase value="c2"> statements // do these if expr == c2 </cfcase> </cfswitch> Adding a <cfbreak> inside of the case, is the same thing as closing the cfcase. This makes CFMX not backwards compatible with CF5.[Top]
Recommended Books
COLDFUSION MX Web Application Construction Kit (5th Edition)
Authors: Ben Forta and Nate Weiss
1500 pages
[Top]
Web Sites
[Top]