Adobe ColdFusion 8

cfdefaultcase

Description

Used only inside the cfswitch tag body. Contains code to execute when the expression specified in the cfswitch tag does not match the value specified by a cfcase tag.

Category

Flow-control tags

Syntax

<cfdefaultcase>

See also

cfcase, cfswitch; "cfswitch, cfcase, and cfdefaultcase" in the ColdFusion Developer's Guide

History

ColdFusion MX: Changed placement requirements: this tag does not have to follow all cfcase tags in the cfswitch tag body.

Usage

The contents of the cfdefaultcase tag body executes if the expression attribute of the cfswitch tag does not match any of the values specified by the cfcase tags in the cfswitch tag body. The contents of the cfdefaultcase tag body can include HTML and text, and CFML tags, functions, variables, and expressions.

You can specify only one cfdefaultcase tag within a cfswitch tag. You can put the cfdefaultcase tag at any position within a cfswitch statement; it is not required to be the last item, but it is good programming practice to put it last.

Example

<!--- The following example displays a grade based on a 1-10 score.
        Several of the cfcase tags match more than one score.
        For simplicity, the example sets the score to 7. --->
<cfset score="7">
<cfswitch expression="#score#">
    <cfcase value="10">
        <cfset grade="A">
    </cfcase>
    <cfcase value="9;8" delimiters=";">
        <cfset grade="B">
    </cfcase>
    <cfcase value="7;6" delimiters=";">
        <cfset grade="C">
    </cfcase>
    <cfcase value="5;4;" delimiters=";">
        <cfset grade="D">
    </cfcase>
    <cfdefaultcase>
        <cfset grade="F">
    </cfdefaultcase>
</cfswitch>
<cfoutput>
    Your grade is #grade#
</cfoutput>