<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>
<cfscript>
//Script example
switch(1){
case 1:
result = 1;
break;
case 0:
result = 0;
break;
default:
result = "defaultCase";
}
writeDump(result);
</cfscript>
</cfoutput>
See also
- Core CFML Language
- <cfcase>
- <cfdefaultcase>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)