# CFBREAK

Used to break out of a CFLOOP. See Breaking out of a loop, later in this chapter, for more information.

### Syntax

    <CFBREAK>

### Example

    <!--- This example shows the use of CFBREAK to exit
    a loop when a condition is met --->

    <!--- select a list of courses and use CFLOOP to find a condition
    and then break the loop --->
    <CFQUERY NAME="GetCourses" DATASOURCE="cfsnippets">
    SELECT *
    FROM courses
    ORDER by Number
    </CFQUERY>
    <HTML>
    <HEAD>
    <TITLE>
    CFBREAK Example
    </TITLE>
    </HEAD>
    <BODY bgcolor=silver>

    <H1>CFBREAK Example</H1>
    <P>This example uses CFLOOP to cycle through a query to find a desired
    value. (In our example, a list of values corresponding to courses in the
    cfsnippets datasource).
    When the conditions of the query are met, CFBREAK stops the loop.
    ...
    <!--- loop through the query until desired value is found,
       then use CFBREAK to exit the 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>

    </BODY>
    </HTML>