<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFSWITCH</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">CFSWITCH</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>
Evaluates a passed expression and passes control to the cfcase tag that matches the expression result. You can, optionally, code a cfdefaultcase tag, which receives control if there is no matching cfcase tag value.
</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;cfswitch 
   expression = &quot;expression&quot;&gt;
      one or more cfcase tags
      zero or one cfdefaultcase tags
&lt;/cfswitch&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>
cfcase, cfdefaultcase, cfabort, cfloop, cfbreak, cfexecute, cfexit, cfif, cflocation, cfrethrow, cfthrow, cftry; "cfswitch, cfcase, and cfdefaultcase" 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">History</span>
<p>
ColdFusion&#160;MX: Changed cfdefaultcase tag placement requirements: you can put the cfdefaultcase tag at any position within a cfswitch statement; it is not required to be the last&#160;item. 
</p>

<p>

</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">Usage</span>
<p>
This tag requires an end tag. All code within this tag must be within a cfcase or cfdefaultcase tag. Otherwise, ColdFusion throws an error.
</p>

<p>
Use this tag followed by one or more cfcase tags. Optionally, include a cfdefaultcase tag. This tag selects the matching alternative from the cfcase and cfdefaultcase tags, jumps to the matching tag, and executes the code between the cfcase start and end tags.
</p>

<p>
The cfswitch tag provides better performance than a series of cfif/cfelseif tags, and the code is easier to read. 
</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 example shows the use of cfswitch and cfcase to 
exercise a case statement in CFML. ---&gt;
&lt;cfquery name = &quot;GetEmployees&quot; dataSource = &quot;cfdocexamples&quot;&gt;
   SELECT Emp_ID, FirstName, LastName, EMail, Phone, Department
   FROM   Employees
&lt;/cfquery&gt;

&lt;h3&gt;cfswitch Example&lt;/h3&gt;
&lt;!--- By outputting the query and using cfswitch, we classify the 
output without using a cfloop construct. ---&gt;
&lt;p&gt;Each time the case is fulfilled, the specific information is printed; 
if the case is not fulfilled, the default case is output &lt;/p&gt; 
&lt;cfoutput query=&quot;GetEmployees&quot;&gt; 
&lt;cfswitch expression=&quot;#Trim(Department)#&quot;&gt; 
   &lt;cfcase value=&quot;Sales&quot;&gt; 
      #FirstName# #LastName# is in &lt;b&gt;sales&lt;/b&gt;&lt;br&gt;&lt;br&gt; 
   &lt;/cfcase&gt; 
   &lt;cfcase value=&quot;Accounting&quot;&gt; 
      #FirstName# #LastName# is in &lt;b&gt;accounting&lt;/b&gt;&lt;br&gt;&lt;br&gt; 
   &lt;/cfcase&gt; &lt;cfcase value=&quot;Administration&quot;&gt; 
      #FirstName# #LastName# is in &lt;b&gt;administration&lt;/b&gt;&lt;br&gt;&lt;br&gt; 
   &lt;/cfcase&gt; 
   &lt;cfdefaultcase&gt; 
      #FirstName# #LastName# is not in Sales, Accounting, or
         Administration.&lt;br&gt;&lt;br&gt;
   &lt;/cfdefaultcase&gt; 
&lt;/cfswitch&gt; 
&lt;/cfoutput&gt; 
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="EXPRESSION">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">EXPRESSION</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>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>ColdFusion expression that yields a scalar value. ColdFusion converts integers, real numbers, Booleans, and dates to numeric values. For example, True, 1, and 1.0 are all equal. </p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
