User Guide Cancel

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

cfcasecfswitchcfswitchcfcase, and cfdefaultcase in the Developing ColdFusion Applications

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

 

<cfset language = "" />
<cfswitch expression="#language#">
<cfcase value="ColdFusion">
The 2018 release of ColdFusion.
</cfcase>
<cfdefaultcase>
Bring your own language!
</cfdefaultcase>
</cfswitch>
<cfset language = "" /> <cfswitch expression="#language#"> <cfcase value="ColdFusion"> The 2018 release of ColdFusion. </cfcase> <cfdefaultcase> Bring your own language! </cfdefaultcase> </cfswitch>
<cfset language = "" />
<cfswitch expression="#language#">
    <cfcase value="ColdFusion">
        The 2018 release of ColdFusion.
    </cfcase>
    <cfdefaultcase>
        Bring your own language!
    </cfdefaultcase>
</cfswitch>

Output

Bring your own language!

Get help faster and easier

New user?