Appendix D: Conditional expressions.

SIMULA allows any expression to contain a number of alternatives, one of which is chosen for evaluation according to one or more conditions. These are all extensions of the simplest form, which may be nested to produce arbitrarily complicated variants.

In practice it is wise to use these with caution.

Some simple examples are:

  1. Integer expression.
          IntVal := if A=B then IntVal + 1 else IntVal = 2
    
    Here IntVal is incrreased by 1 if A=B, otherwise it is increased by 2.

  2. Object expression.
          (if A=B then Obj1 else Obj2).Val := 6
    
    Here the value 6 is assigned to attribute Val of Obj1 if A=B, otherwise it is assigned to attribute Val of Obj2. Note that the reference expression must be enclosed in brackets to avoid ambiguity and that Obj1 and Obj2 must be qualified by the same class.

These examples should give a sufficient idea of the use of this feature.