iif()

The if() system function implements "immediate if" functionality, similar to the ? : operator available in C#, Swift and Java, and if/then/else Expressions in Oxygene. It evaluates the first boolean parameter, and depending on whether it is true or false, it evaluates and returns either the second or third parameter. It is important to note that other expressions will not be executed at all.

Syntax:

method iif(aCondition: Boolean; aTrueExpression: Value; aFalseExpression: Value := nil): Value;
Value iif(bool condition, Value trueExpression, value falseExpression);
func iif(_ condition: Boolean, _ trueExpression: Value, _ falseExpression: Value = nil): Value
Value iif(bool condition, Value trueExpression, value falseExpression);

The return value of iif will be the closest common ancestor of the two values. For example

iif(mybool, "yes", "no")

would be treated as a String, while

iif(mybool, "yes", 0);

would be typed as an Object at compile-time (though the result would eventually be a String or an Integer at runtime).

If no third parameter is provided and the condition evaluates to false, iif() returns the default value for the type (e.g. 0 for numbers, or nil/null for reference types).

See Also