Fortran IF statement with numbers/labels rather than another statement
此Fortran代码是什么意思:
1 2 3 4 5 | IF (J1-3) 20, 20, 21 21 J1 = J1 - 3 20 IF (J2-3) 22, 22, 23 23 J2 = J2 - 3 22 CONTINUE |
我在旧项目中见过,但我不知道带有数字(标签)的IF意味着什么。
这是FORTRAN 77的算术
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 , ands3 are each the statement label of an executable statement that appears in the same program unit as the arithmeticIF statement. The same statement label may appear more than once in the same arithmeticIF statement.Execution of an arithmetic
IF statement causes evaluation of the expressione followed by a transfer of control. The statement identified bys1 ,s2 , ors3 is executed next as the value ofe is less than zero, equal to zero, or greater than zero, respectively.
对于您问题中的示例,从上面的最后一句话开始,
-
如果
J1-3 < 0 语句20将被执行 -
如果
J1-3 = 0 语句20也将被执行 -
如果
J1-3 > 0 语句21将被执行
编辑:编写此代码的一种现代且更具可读性的方法是:
1 2 | if (J1-3 > 0) J1 = J1 - 3 if (J2-3 > 0) J2 = J2 - 3 |