<cfcase>
Handle one case of a <cfswitch>
This tag must have a body.
This tag is also supported within <cfscript>
<cfcase
value=string
delimiters=string
><!--- body ---></cfcase>
| Attribute | Description |
|---|---|
value
string, required
|
edit
One or more constant values that cfswitch compares to the specified expression case-insensitive comparison. If a value matches the expression, cfswitch executes the code between the cfcase start and end tags. Separate multiple values with a comma or other delimiter, as specified in the delimiters parameter. Duplicate value attributes are not allowed and causes a runtime error. |
delimiters
string, optional
|
edit
Specifies the character that separates multiple entries in a list of values. You can specify multiple delimiter characters and you can use any of them to separate the values to be matched. Delimiters can only be used in the tag syntax. Default delimiter: , Note: in <cfscript>, delimitered values are not supported for case statements. Use an individual case statement for each value. |
Examples
editTag syntax
<cfset expr = 2>
<cfswitch expression="#expr#">
<cfcase value=1>
this is from case 1
</cfcase>
<cfcase value=2$3$4 delimiters="$">
this is from case 2
</cfcase>
<cfcase value=5,6,7>
this is from case 3
</cfcase>
<cfdefaultcase>
this is from default part
</cfdefaultcase>
</cfswitch>
Script syntax
expr = 1;
switch(expr){
case 1:
result = 1;
break;
case 2:
case 3:
result = "2 or 3";
break;
case 0:
result = 0;
break;
default:
result = "defaultCase";
}
dump( result );
See also
- <cfdefaultcase>
- <cfswitch>
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)