next up previous 63
Next: The LOOP Structure
Up: Control Structures
Previous: Control Structures


The IF structure

The IF structure is essentially the same as the block IF of FORTRAN. It has the following general form:
    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


next up previous 63
Next: The LOOP Structure
Up: Control Structures
Previous: Control Structures

ICL The Interactive Command Language for ADAM
Starlink Guide 5
J A Bailey
A J Chipperfield

9th June 1998
E-mail:starlink@jiscmail.ac.uk

Copyright © 2013 Science and Technology Facilities Council