Understanding Functions

Conditional Expressions

Sometimes you may wish to produce an expression which includes one or more tests for particular conditions, like this:

If A then B else C

There are 4 functions which are designed specifically to support this. These are:

In each case, they take 3 parameters, the first of which is a boolean expression. If this parameter is True, the function returns the 2nd parameter. Otherwise it returns the 3rd parameter. There is one such function for each of the basic data types, except Bool. There is no need for a function of this kind for booleans as the same result can be achieved by using And and Or and bracketing boolean expressions appropriately:

If A then B else C

is equivalent to

(A and B) or (Not(A) and C)

where A, B and C are all boolean expressions.