Used only inside the cfswitch tag body. Contains code to execute when the expression specified in the cfswitch tag has one or more specific values. Note the difference in the tag and script syntax when providing multiple values for a case.

 <cfcase value="">

 case "apple":

cfcase Attribute Reference


The value or values that the expression attribute of the cfswitch tag must match. To specify multiple matching values, for tag syntax, separate the values with the delimiter character; for script syntax list each on the same line. The value or values must be simple constants or constant expressions, not variables.

Default: ,

Specifies the delimiter character or characters that separate multiple values to match. If you specify multiple delimiter characters, you can use any of them to separate the values to be matched. Used only for tag syntax. Values:
  • ,
  • ;
  • |
  • :

Examples sample code using the cfcase tag

Script Syntax

fruit = "";
switch(fruit) {
    case "Apple":
        writeOutput("I like apples!");
    case "Orange": case "Citrus":
        writeOutput("I like oranges!");
    case "Kiwi":
        writeOutput("I like kiwi!"); 
        writeOutput("Fruit, what fruit?"); 

Expected Result: Fruit, what fruit?

Tag Syntax

<cfset fruit = "Orange"> 
<cfswitch expression="#fruit#"> 
    <cfcase value="Apple">I like apples!</cfcase>
    <cfcase value="Orange;Citrus" delimiters=";">I like oranges!</cfcase> 
    <cfcase value="Kiwi">I like kiwi!</cfcase>
    <cfdefaultcase>Fruit, what fruit?</cfdefaultcase> 

Expected Result: I like oranges!

Fork me on GitHub