next up previous contents
Next: Nested and Named IF Up: Control Flow Previous: IF Statement

 

IF Construct

The block-IF is more flexible than the single statement IF since there can be a number of alternative mutually exclusive branches guarded by (different) predicates. The control flow is a lot more structured than if a single statement IF plus GOTO statements were used. The scenario is that the predicates in the IF or ELSEIF lines are tested in turn, the first one which evaluates as true transfers control to the appropriate inner block of code; when this has been completed control passes to the ENDIF statement and thence out of the block. If none of the predicates are true then the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 (if present) is executed.

Syntax,

 
[ tex2html_wrap_inline21746  name  tex2html_wrap_inline21748 :]IF( tex2html_wrap_inline21746  logical-expression  tex2html_wrap_inline21748 )THEN

tex2html_wrap_inline21746  then-block tex2html_wrap_inline21748

[ ELSEIF( tex2html_wrap_inline21746  logical-expression tex2html_wrap_inline21748 )THEN [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

tex2html_wrap_inline21746  elseif-block tex2html_wrap_inline21748

... ]

[ ELSE [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 ]

END IF [ tex2html_wrap_inline21746  name tex2html_wrap_inline21748 ]

The first branch to have a .TRUE. valued tex2html_wrap_inline21746  logical-expression tex2html_wrap_inline21748 is the one that is executed. If none are found then the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 , if present, is executed.

For example,

    IF (x .GT. 3) THEN
     CALL SUB1
    ELSEIF (x .EQ. 3) THEN
     CALL SUB2
    ELSE
     CALL SUB3
    ENDIF

(A further IF construct may appear in the tex2html_wrap_inline21746  then-block tex2html_wrap_inline21748 , the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 or the tex2html_wrap_inline21746  elseif-block tex2html_wrap_inline21748 . This is now a nested IF structure.)

Statements in either the tex2html_wrap_inline21746  then-block tex2html_wrap_inline21748 , the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 or the tex2html_wrap_inline21746  elseif-block tex2html_wrap_inline21748 may be labelled but jumps to such labelled statements are permitted only from within the block containing them. Entry into a block-IF construct is allowed only via the initial IF statement. Transfer out of either the tex2html_wrap_inline21746  then-block tex2html_wrap_inline21748 , the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 or the tex2html_wrap_inline21746  elseif-block tex2html_wrap_inline21748 is permitted but only to a statement entirely outside of the whole block defined by the IF...END IF statements. A transfer within the same block-IF between any of the blocks is not permitted.

Certain types of statement, eg, END SUBROUTINE, END FUNCTION or END PROGRAM, statement are not allowed in the tex2html_wrap_inline21746  then-block tex2html_wrap_inline21748 , the tex2html_wrap_inline21746  else-block tex2html_wrap_inline21748 or the tex2html_wrap_inline21746  elseif-block tex2html_wrap_inline21748 .


next up previous contents
Next: Nested and Named IF Up: Control Flow Previous: IF Statement

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.