Name
CFSWITCH
Synopsis
<CFSWITCH EXPRESSION="expression"> <CFCASE VALUE="value" DELIMITERS="delimiter">HTML and CFML</CFCASE> <CFCASE VALUE="value" DELIMITERS="delimiter">HTML and CFML</CFCASE> ... <CFDEFAULTCASE>HTML and CFML</CFDEFAULTCASE> </CFSWITCH>
Evaluates an expression against multiple values until a match is
made. Once a match has been made, CFSWITCH passes
control to the appropriate CFCASE tag where
additional action can take place. If no VALUE
matches EXPRESSION, the code between the
CFDEFAULTCASE tags is executed.
CFSWITCH/CFCASE/CFDEFAULTCASE
is similar in function to
CFIF/CFELSEIF/CFELSE.
CFSWITCH is significantly faster than using
multiple CFIF statements however, because the
CFCASE statements are evaluated when the
ColdFusion language parser compiles the template into p-code. This
means that there is no difference in execution time between a
CFSWITCH statement with one
CFCASE statement or 1,000
CFCASE statements. CFIF
statements on the other hand are evaluated one by one at execution
time until one statement evaluates True.
Attributes
-
EXPRESSION="expression" Any ColdFusion expression that evaluates to a simple value (string, number, Boolean, date/time). Required.
-
VALUE="value" A value or delimited list of values
CFSWITCHuses to perform a case-insensitive comparison against the specified EXPRESSION. If a value listed inVALUEmatchesEXPRESSION, the code between theCFCASEtags is executed. Required.-
DELIMITERS="delimiter" Specifies the character ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access