next up previous contents
Next: Visualisation of IF ... Up: Control Constructs Previous: Visualisation of the IF

 

IF ... THEN .... ELSEIF Construct

The IF construct has the following syntax,

 
IF(< logical-expression >)THEN

< then-block >

[ ELSEIF(< logical-expression >)THEN

< elseif-block >

... ]

[ ELSE

< else-block > ]

END IF

The first branch to have a true < logical-expression > is the one that is executed. If none are found then the < else-block >, if present, is executed.

For example,

    IF (x .GT. 3) THEN
     CALL SUB1
    ELSEIF (x .EQ. 3) THEN
     A = B*C-D
    ELSEIF (x .EQ. 2) THEN
     A = B*B
    ELSE
     IF (y .NE. 0) A=B
    ENDIF

IF blocks may also be nested.

For more information, click here gif


next up previous contents
Next: Visualisation of IF ... Up: Control Constructs Previous: Visualisation of the IF

©University of Liverpool, 1997
Wed May 28 23:37:18 BST 1997
Not for commercial use.