IIf is a language function to perform an immediate or inline conditional assignment.
IIf
is an abbreviation variously for Inline If or Immediate If and is available in many programming and script languages, IIf
is implemented as a Function
which means it returns a value. In code, these typically take the form:
result = IIf(condition, TruePart, FalsePart)
The value of result
afterwards depends on the evaluation of condition.
A multi-line If
block could perform the same action but would be an If Statement
. The statement form could include any number of other actions such as invoke other methods. On the other hand, IIf
simply results in a conditional assignment and cannot invoke other code.
Some languages also support a 'conditional operator', sometimes called a ternary operator, which works similar to IIf
, but may offer other benefits.