378
CFML Language Reference
IIf
The function evaluates its condition as a Boolean. If the result is TRUE, it returns the
value of Evaluate(string_expression1); otherwise, it returns the value of
Evaluate(string_expression2).
Prior to using IIf, please read the Usage section and Note carefully. The IIf function is
primarily intended for the conditional processing of dynamic expressions.
For general conditional processing, see
CFIF/CFELSEIF/CFELSE
.
For error handling, see
CFTRY/CFCATCH
.
See also
DE
and
Evaluate
.
Syntax
IIf
(
condition, string_expression1, string_expression2)
condition
Any expression that can be evaluated as a Boolean.
string_expression1
Valid string expression to be evaluated and returned if condition is TRUE.
string_expression2
Valid string expression to be evaluated and returned if condition is FALSE.
Usage
The IIf function is a shortcut for the following construct:
<CFIF condition>
<CFSET result=Evaluate(string_expression1)>
<CFELSE>
<CFSET result=Evaluate(string_expression2)>
</CFIF>
returning result.
The expressions string_expression1 and string_expression2 must be string expressions,
so that they do not get evaluated immediately as the arguments of IIf. For example:
IIf(y is 0, DE("Error"), x/y)
will generate error if y=0 because the third argument is the value of x/0 (not a valid
expression).
Remember that ColdFusion evaluates string_expression1 and string_expression2. To
return the string itself instead of evaluate the expression, use the
DE
(delay evaluation)
function.
Note
If you use pound signs (#) in either string_expression1 or
string_expression2, ColdFusion evaluates the part of the expression that
is in pound signs first. By misusing pound signs, you can skew the results
of the IIf function. In particular, if you use pound signs around the whole
expression in string_expression1, it can cause the function to fail with the
Summary of Contents for COLDFUSION 4.5-CFML LANGUAGE
Page 1: ...Allaire Corporation CFML Language Reference ColdFusion 4 5...
Page 207: ...Chapter 1 ColdFusion Tags 183 CFCATCH CFTRY BODY HTML...
Page 224: ...200 CFMLLanguageReference CFOUTPUT P Text within CFOUTPUT is always shown CFOUTPUT BODY HTML...
Page 336: ...312 CFMLLanguageReference CFIF BODY HTML...
Page 404: ...380 CFMLLanguageReference DE It is morning CFOUTPUT P BODY HTML...
Page 413: ...Chapter 2 ColdFusion Functions 389 Customer BalanceDue BR CFOUTPUT CFIF BODY HTML...
Page 483: ...Chapter 2 ColdFusion Functions 459 CFOUTPUT CFLOOP BODY HTML...
Page 584: ...560 CFMLLanguageReference...
Page 594: ...570 CFMLLanguageReference...