Conditional statements (IF) (THEN) (ELSEIF) (ELSE)(ENDIF)

EASI allows the conditional execution of statements with the IF statement. The IF statement can have various forms. The simplest is a single test, which if successful, will cause a single statement to be executed:

IF (condition) statement

The condition to be tested may be any valid logical expression. For example:

IF ( a = 3 ) print "success"

If the variable a is set to the value 3, then the print statement is executed. If a is not set to 3, then the print statement is ignored. For a complete discussion on conditions, see the section on logical expressions. Any valid EASI statement can be put in place of the print statement. Note that when the equals operator "=" is used in an IF statement, it is used as a test of equality, and no assignment is performed. This is unlike the usual use of the equals operator outside of an IF statement where it will cause variable assignment to take place.

A more complex form of the IF statement allows the execution of a block of statements if the test is satisfied, instead of just a single statement:

IF (condition) THEN
 statement list
ENDIF

where

[statement list] is a list of command statements to execute if
                 the condition is true.

For example:

IF ( channel > 10 ) THEN
 print "Error, channel is too large!"
 print "Channel will be reset to default value of 1"
 channel = 1
ENDIF

There may be an arbitrarily long list of statements between the IF and ENDIF statements, to be executed if the result of the condition is TRUE. If the condition evaluates to false, then the next statement to be executed is the first statement after the ENDIF. Note that a common source of syntax errors is accidently omitting the THEN keyword at the end of the IF statement.

The use of an ELSE clause with the IF statement allows a second block of code to be executed if the condition tested in the IF statement fails:

 IF (condition) THEN
   statement list1
 ELSE
   statement list2
 ENDIF

For example:

 IF ( a > b ) THEN
   max = a
 ELSE
   max = b
 ENDIF

Finally, the ELSEIF clause can be used to test additional conditions in an IF statement:

 IF (condition) THEN
   statement list1
 [ELSEIF (condition)
   statement list2]
 [ELSE
   statement list3]
 ENDIF

For example:

 if ( NumberOfPixels < 1 ) then
   print "Window is too small"
 elseif ( NumberOfPixels > 100000 ) then
   print "Window is too large"
 else
   print "Window size is acceptable"
 endif

The ELSE clause may be omitted, and their may also be any number of ELSEIF clauses instead of just one.

IF statements may be nested within other IF statements, in this case it is very useful to use indentation to make the program logic easier to understand.

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.