Macromedia coldfusion 4.5-cfml language reference User Manual

Page of 608
210
CFML Language Reference 
CFSWITCH/CFCASE/CFDEFAULTCASE
Used with CFCASE and CFDEFAULTCASE, the CFSWITCH tag 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.
Syntax
<CFSWITCH EXPRESSION="expression">
<CFCASE VALUE="value" DELIMITERS="delimiters">
   HTML and CFML tags
</CFCASE>
additional <CFCASE></CFCASE> tags
<CFDEFAULTCASE>
   HTML and CFML tags
</CFDEFAULTCASE>
</CFSWITCH>
EXPRESSION
Required. Any 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. 
VALUE
Required. 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 an alternative delimiter, as specified in 
the DELIMITERS parameter. Duplicate value attributes are not allowed and will 
cause a runtime error.
DELIMITERS
Optional. Specifies the character that separates multiple entries in a list of values. 
The default delimiter is the comma (,). 
Usage
Use CFSWITCH followed by one or more CFCASE tags, optionally ending with a 
CFDEFAULTCASE tag. The CFSWITCH tag selects the matching alternative from the 
specified CFCASE and CFDEFAULTCASE tags and jumps to the matching tag, 
executing the code between the CFCASE start and end tags. There is no need to 
explicitly break out of the CFCASE tag, as there is in some other languages.
You can specify only one CFDEFAULTCASE tag within a CFSWITCH tag. CFCASE tags 
cannot appear after the CFDEFAULTCASE tag.
CFSWITCH provides better performance than a series of CFIF/CFELSEIF tags and the 
resulting code is easier to read.