User Guide Cancel

cfelse

 

Description

Used as the last control block in a cfif tag block to handle any case not identified by the cfif tag or a cfelseif tag.

Category

Flow-control tags

Syntax

<cfif expression>
HTML and CFML tags <cfelseif expression>
HTML and CFML tags
<cfelse>
HTML and CFML tags
</cfif>
<cfif expression> HTML and CFML tags <cfelseif expression> HTML and CFML tags <cfelse> HTML and CFML tags </cfif>
<cfif expression> 
HTML and CFML tags <cfelseif expression> 
HTML and CFML tags 
<cfelse> 
HTML and CFML tags 
</cfif>

See also

cfifcfelseifcfabortcfbreakcfexecutecfexitcflocationcfloopcfswitchcfthrowcftry

Usage

If the values of the expressions in the containing cfif tag and all cfelseif tags are no, ColdFusion processes the code between this tag and the cfif end tag. This tag must be inside a cfif tag block. It does not require an end tag. For more information and an example, see cfif.

Example

 

<cfset value = 10>
<cfif value GT 20>
<cfoutput>Greater than 10</cfoutput>
<cfelseif value EQ 8>
<cfoutput>Equal to 8</cfoutput>
<cfelse>
<cfoutput>#value#</cfoutput>
</cfif>
<cfset value = 10> <cfif value GT 20> <cfoutput>Greater than 10</cfoutput> <cfelseif value EQ 8> <cfoutput>Equal to 8</cfoutput> <cfelse> <cfoutput>#value#</cfoutput> </cfif>
<cfset value = 10> 
<cfif value GT 20> 
    <cfoutput>Greater than 10</cfoutput> 
<cfelseif value EQ 8> 
    <cfoutput>Equal to 8</cfoutput> 
<cfelse> 
    <cfoutput>#value#</cfoutput> 
</cfif>

Output

10

Script example

 

<cfscript>
value=10
if (value > 10){
writeOutput("Value is greater than 10")
}
else if(value < 10){
writeOutput("Value is less than 10")
}
else {
writeOutput("Value is 10")
}
</cfscript>
<cfscript> value=10 if (value > 10){ writeOutput("Value is greater than 10") } else if(value < 10){ writeOutput("Value is less than 10") } else { writeOutput("Value is 10") } </cfscript>
<cfscript>
    value=10
    if (value > 10){
        writeOutput("Value is greater than 10")
    }
    else if(value < 10){
        writeOutput("Value is less than 10")
    }
    else {
        writeOutput("Value is 10")
    }
</cfscript>

Output

Value is 10

Get help faster and easier

New user?