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).

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.





 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.