The IF - ELSE branch

The following control statements are used for IF-ELSE branches:

$IF, $ELSE, $ELSEIF, $ENDIF.

Syntax:

Branching always starts with

$IF=..

and always ends with

$ENDIF

Control statements

$ELSE

and

$ELSEIF

are optional and serve to set up multiple branches.

Attention

attention

The condition in the $IF control block is checked by verifying the mathematical expression for "true” or "not true” (TRUE and FALSE). To be able to also use decimal variables, the jump condition is regarded as fulfilled (TRUE) if...

...the absolute value of the mathematical expression is > or = 0.5.

Programing Example

prg_example

The IF - ELSE branch

N10 ...

N20 $IF P1      Only if |P1| is greater or equal to 0.5 are the
                statements N30 to N50 executed.

N30 ...

N40

N50

N60 $ENDIF

However, the following is also possible:

N10 ...

N20 $IF P1 >= 0.5    Only if P1 is greater or equal to 0.5 are the

                     statements N30 to N50 executed.

N30 ...

N40

N50

N60 $ENDIF

or:

N10 ...

N20 $IF P1 > P2      Only if P1 is greater than P2 are the statements
                     N30 to N50 executed, otherwise N70 to N90

N30 ...

N40 ...

N50 ...

N60 $ELSE

N70 ...

N80 ...

N90 ...

N100 $ENDIF

These use of ELSEIF permits:

N10 ...

N20 $IF P1 == 0     Only if P1 is equal to 0 are the statements N30
                    to N50 executed, otherwise a check is made in the
                    $ELSEIF condition whether P2 is >= 0.5 and
                    accordingly N70 to N90 or N110 to N130 are executed.

N30 ...

N40

N50

N60 $ELSEIF P2>=0.5  The $ELSEIF conditions is used to form
                     nested branches.

N70 ...

N80

N90

N100 $ELSE

N110 ...

N120

N130

N140 $ENDIF

Attention

attention

The C programming language also makes a distinction in syntax between

Assignment: P5 = 3

and

Comparison: $IF P5 == 3

The following applies to Version 2.3 and earlier: As mathematical expressions expect always the sequence…

Operator -> Term -> Operator -> Term -> etc.

…expressions preceded by a minus sign must be bracketed in comparison operation ("-" is interpreted as operator).

Programing Example

prg_example

$IF P1 >= -5     incorrect since term->operator->operator->term

$IF P1 >= [-5]   correct since term->operator->term->operator->term