<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFBREAK</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFBREAK</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Used within a cfloop or cfswitch tag. Breaks out of a loop or switch block. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Flow-control tags
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cfbreak&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfabort, cfexecute, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry; "cfloop and cfbreak" in Chapter&#160;2, "Elements of CFML," in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;!--- This shows the use of cfbreak to exit a loop when a condition is met.---&gt;
&lt;!--- Select courses; use cfloop to find a condition; then break the loop. ---&gt;
&lt;!--- Check that number is numeric. ---&gt;
&lt;cfif IsDefined(&quot;form.course_number&quot;)&gt;
   &lt;cfif Not IsNumeric(form.course_number)&gt;
      &lt;cfabort&gt; 
   &lt;/cfif&gt; 
&lt;/cfif&gt; 
&lt;cfquery name=&quot;GetCourses&quot; datasource=&quot;cfdocexamples&quot;&gt;
   SELECT * 
   FROM Courses 
   ORDER by course_number 
&lt;/cfquery&gt;

&lt;p&gt; 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.
&lt;p&gt; Please enter a Course Number, and hit the &quot;submit&quot; button: 
&lt;form action=&quot;cfbreak.cfm&quot; method=&quot;POST&quot;&gt; 
   &lt;select name=&quot;courseNum&quot;&gt; 
      &lt;cfoutput query=&quot;GetCourses&quot;&gt; 
         &lt;option value=&quot;#course_number#&quot;&gt;#course_number#
      &lt;/cfoutput&gt; 
   &lt;/select&gt; 
   &lt;input type=&quot;Submit&quot; name=&quot;&quot; value=&quot;Search on my Number&quot;&gt; 
&lt;/form&gt; 
&lt;!--- If the courseNum variable is not defined, 
      don&#39;t loop through the query.---&gt;
&lt;cfif IsDefined (&quot;form.courseNum&quot;) IS &quot;True&quot;&gt;
&lt;!--- Loop through query until value found, then use CFBREAK to exit query.---&gt;
   &lt;cfloop query=&quot;GetCourses&quot;&gt; 
      &lt;cfif GetCourses.course_number IS form.courseNum&gt; 
         &lt;cfoutput&gt; 
            &lt;h4&gt;Your Desired Course was found:&lt;/h4&gt; 
            &lt;pre&gt;#course_number# #descript#&lt;/pre&gt;
         &lt;/cfoutput&gt; 
         &lt;cfbreak&gt; 
      &lt;cfelse&gt; 
         &lt;br&gt; Searching... 
      &lt;/cfif&gt; 
   &lt;/cfloop&gt; 
&lt;/cfif&gt; 
</pre>
         </td>
      </tr>
   </table>
   </div>

  </body>
</html>
