IF expression
statements
ELSE IF expression
statements
ELSE IF expression
statements
ELSE
statements
END IF
The expressions (which must give logical values) are evaluated in turn until
one is found to be true, and the following statements are then executed.
If none of the expressions
are true the statements following ELSE are executed.
Every IF structure must begin with IF and end with END IF (or ENDIF). The ELSE IF (ELSEIF) and ELSE clauses are optional, so the simplest IF structure would have the form:
IF expression
statements
ENDIF
The following example illustrates the use of the IF structure, and shows how
one IF structure may be nested within another.
PROC QUADRATIC A,B,C
{ A Procedure to find the roots of the quadratic equation }
{ A * X**2 + B * X + C = 0 }
IF A=0 AND B=0
PRINT The equation is degenerate
ELSE IF A=0
PRINT Single Root is (-C/B)
ELSE IF C=0
PRINT The roots are (-B/A) and 0
ELSE
RE = -B/(2*A)
DISCRIMINANT = B*B - 4*A*C
IM = SQRT(ABS(DISCRIMINANT)) / (2*A)
IF DISCRIMINANT >= 0
PRINT The Roots are (RE + IM) and (RE - IM)
ELSE
PRINT The Roots are complex
PRINT (RE) +I* (IM) and
PRINT (RE) -I* (IM)
ENDIF
ENDIF
END PROC
ICL The Interactive Command Language for ADAM