Contents - Index


IF - THEN - ELSE and IFNOT

 

Both single and multiple line formats for IF - THEN - ELSE statements are allowed in Internal Functions and Procedures. IF-THEN-ELSE can not be used in the main program or in Subprograms and Modules. See the IF function as one possible alternative.   IF - THEN - ELSE statements use logical (also called comparison) operators.  An example of the single line format is:

 

     IF (X<Y) THEN A:=5 ELSE A:=6

 

Note that the single line format can involve only one THEN and one ELSE keyword and only one equation can be provided after each of these keywords, all on the same line.

 

Multiple line IF - THEN - ELSE statements allow a group of statements to be executed.  The format is illustrated in the following example.

 

     IF (X<Y) THEN

        A:=2

        B:=3

     ELSE

        A:=25

        B:=35

     ENDIF

 

The THEN keyword is required and it must be preceded by one or more spaces.  An ELSE (or ENDIF) keyword terminates the first group of statements.  The ENDIF keyword terminates the IF statement.  An ENDIF keyword is required if the multiple line format is used.  The ENDIF keyword is not used in the single line format.

 

Logical operations using the keywords AND and OR may be used in the IF-THEN-ELSE statements, as in the following example.

 

    IF (X<Y) OR (X>0) THEN B:=106

 

Note that the use of parentheses surrounding the logical test is required.

 

EES will process the logical operations from left to right.  When using more than a single AND or OR, it may be necessary to use parentheses to achieve the desired result.  A simple example follows.

 

   IF (X<Y) AND ((X<Z) OR (Y<Z)) then B:=106

 

Without the parentheses, EES would have logically ANDed (X<Y) and (X<Z) and then logically ORed this result with (Y<Z).

 

The IFNOT keyword is similar to the IF keyword and has the same form.  The not equal operator (<>) can be used in the IF and IFNOT statements.  The following two statements are equivalent:

 

     IFNOT (X=Y) THEN GOTO 10

     IF (X<>Y) THEN GOTO 10

 

Logic can also be implemented with CASE and REPEAT - UNTIL statements.  

 

The Warning and  Error Procedures are often used within IF - THEN - ELSE and CASE statements.

 

See also the $IF and $IFNOT directives.