next up previous contents index
Next: The For Instruction Up: Control Structures Previous: Control Structures

The If Instruction

There are two variants to the if instruction. The first variant is:


The block is executed only if the expression has the boolean value TRUE.

EXPRESSIONS can be replaced by any complex expression if it delivers a boolean value:

if sqrt (9)-5<0 and TRUE<>FALSE then print("hello world") endif


hello world

Please note that the logic operator `and' is the operator last executed due to its lowest priority. If there is confusion about the execution order, it is recommended to use brackets to make sure the desired result will be achieved.

The second variant of the if operator uses a second block which will be executed as an alternative to the first one. The structure of the second if variant looks like this:

if EXPRESSION then BLOCK1 else BLOCK2 endif

The first BLOCK, here described as BLOCK1, will be executed only if the resulting value of EXPRESSION is `TRUE'. If EXPRESSION delivers `FALSE', BLOCK2 will be executed.
Tue Nov 28 10:30:44 MET 1995