Iif - MACROMEDIA COLDFUSION 4.5-CFML LANGUAGE Reference

Cfml language reference
Table of Contents

Advertisement

378

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
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
function.
Note
DE
and Evaluate.
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
CFML Language Reference
DE
(delay evaluation)

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-CFML LANGUAGE and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion 4.5

Table of Contents