Description

Creates simple and compound conditional statements in CFML. Tests an expression, variable, function return value, or string. Used, optionally, with the cfelse and cfelseif tags.

Category

Syntax

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

See also

Usage

If the value of the expression in the cfif tag is true, ColdFusion processes all the code that follows, up to any cfelseif or cfelse tag, and then skips to the cfif end tag. Otherwise, ColdFusion does not process the code that immediately follows the cfif tag, and continues processing at any cfelseif or cfelse tag, or with the code that follows the cfif end tag.
When testing the return value of a function that returns a Boolean, you do not have to define the True condition explicitly. This example uses the IsArray function:

<cfif IsArray(myarray)>

If successful, IsArray evaluates to yes, the string equivalent of the Boolean True. This is preferred over explicitly defining the True condition this way:

<cfif IsArray(myarray) IS True>

This tag requires an end tag.

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>

Output

10

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy