<cfswitch>

Used with <cfcase> and <cfdefaultcase>.

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.

This tag must have a body.

This tag is also supported within <cfscript>

<cfswitch expression=string ><!--- body ---></cfswitch>
Attribute Description
expression
string, required

Any CFML expression that yields a scalar value. CFML converts integers, real numbers, Booleans, and dates to numeric values.

Examples

<cfoutput>
	<cfset expr = 2>
	<cfswitch expression="#expr#">
		<cfcase value=1>
			this is from case 2
		</cfcase>
		<cfcase value=2$3$4 delimiters="$">
			this is from case 2
		</cfcase>
		<cfdefaultcase>
			this is from default part
		</cfdefaultcase>
	</cfswitch>
<span class="nb">&lt;cfscript&gt;</span>
<span class="c">//Script example</span>
	<span class="k">switch</span><span class="p">(</span><span class="m">1</span><span class="p">){</span>
		<span class="k">case</span> <span class="m">1</span><span class="p">:</span>
			<span class="nv">result</span> <span class="o">=</span> <span class="m">1</span><span class="p">;</span>
			<span class="k">break</span><span class="p">;</span>
		<span class="k">case</span> <span class="m">0</span><span class="p">:</span>
			<span class="nv">result</span> <span class="o">=</span> <span class="m">0</span><span class="p">;</span>
			<span class="k">break</span><span class="p">;</span>
		<span class="k">default</span><span class="p">:</span>
			<span class="nv">result</span> <span class="o">=</span> <span class="s2">&quot;defaultCase&quot;</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="nf">writeDump</span><span class="p">(</span><span class="nv">result</span><span class="p">);</span>
<span class="nb">&lt;/cfscript&gt;</span>

</cfoutput>

See also