Page 135 - Standard Handbook Of Petroleum & Natural Gas Engineering
P. 135
120 Mathematics
Conditional statements are as follows:
IF(e)sl,sP,s3-Arithmetic if, where e is an arithmetic expression and sl,s2,s3
are statement labels; transfers control to a labeled statement depending on
whether e evaluates to a negative, zero, or positive value, respectively. For
example,
IF(I - 5) 30,40,50
will transfer control to the statement labeled 40 if I = 5.
IF(e)st-Logical if, where e is a logical expression (see Table 1-26 for relational
and logical operators) and st is any executable statement except DO, IF, ELSEIF,
ENDIF, or END. For example,
IF(I.EQ. 1) WRITE( *,*)‘YES’
IF(e) THEN-Block if, where e is a logical expression, followed by a sequence
of statements and completed by an ENDIF statement. The block may include
sub-blocks introduced by one or more ELSEIF statements and/or one ELSE
statement and all sub-blocks may contain nested IF-THEN-ELSE blocks within
them. For example,
IF(1.EQ.J) THEN
x=4
Y=5
ENDIF
IF( 1.EQ.J) THEN
x=4
ELSE
x=5
ENDIF
IF(1.EQ.J) THEN
x=4
ELSEIF(1.EQ.K) THEN
x=5
ELSE
X=Y
ENDIF
The iterative statement in FORTRAN is the DO statement (although others
may be constructed using conditional statements and GOTOs), where
DO st i = init,term,incr
introduces the repetitive section, and st is the label of the executable statement
marking the end of the loop (usually, but not necessarily, a CONTINUE state-
ment), i is the index or control integer variable and init, term, and incr
(optional) are the initial value for i, the terminal value for i, and the increment
of i to be used, respectively. These values must be integer constants, variables,
or expressions in standard FORTRAN 77, but many extensions to the language
allow real values to be used. DO loops may be nested to a level determined by
a specific compiler. For example,

