Conditionals

The if-expression selects from two expressions based on the value of a logical input value and evaluates only the selected expression.

if-expression:
       if if-condition then true-expression else false-expression
if-condition:
      expression
true-expression:
      expression
false-expression:
      expression

The following are examples of if-expressions:

if 2 > 1 then 2 else 1          // 2
if 1 = 1 then "yes" else "no"   // "yes"

The following holds when evaluating an if-expression:

  • If the value produced by evaluating the if-condition is not a logical value, then an error with reason code "Expression.Error" is raised.

  • The true-expression is only evaluated if the if-condition evaluates to the value true.

  • The false-expression is only evaluated if the if-condition evaluates to the value false.

  • The result of the if-expression is the value of the true-expression if the if-condition is true, and the value of the false-expression if the if-condition is false.

  • Errors raised during the evaluation of the if-condition, true-expression, or false-expression are propagated.