Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

fortran90 - Fortran IF statement with numbers/labels rather than another statement

What does this Fortran code mean:

   IF (J1-3) 20, 20, 21
21 J1 = J1 - 3
20 IF (J2-3) 22, 22, 23
23 J2 = J2 - 3
22 CONTINUE

I've seen in old project and I don't have any idea what this IF with numbers (labels) means.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is an arithmetic if statement from FORTRAN 77. Adapted from the FORTRAN 77 specification (emphasis mine):

The form of an arithmetic IF statement is:

IF (e) s1 , s2 , s2

  • where: e is an integer, real, or double precision expression

  • s1, s2, and s3 are each the statement label of an executable statement that appears in the same program unit as the arithmetic IF statement. The same statement label may appear more than once in the same arithmetic IF statement.

Execution of an arithmetic IF statement causes evaluation of the expression e followed by a transfer of control. The statement identified by s1, s2, or s3 is executed next as the value of e is less than zero, equal to zero, or greater than zero, respectively.

For the example in your question, from the last sentence above,

  • If J1-3 < 0 statement 20 will be executed
  • If J1-3 = 0 statement 20 will also be executed
  • If J1-3 > 0 statement 21 will be executed

Edit: A modern and much more readable way to write this would be:

if (J1-3 > 0) J1 = J1 - 3
if (J2-3 > 0) J2 = J2 - 3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...