带有数字/标签的Fortran IF语句而不是其他语句 [英] Fortran IF statement with numbers/labels rather than another statement
问题描述
这个Fortran代码是什么意思:
IF(J1-3)20,20,21
21 J1 = J1-3
20 IF(J2-3)22,22,23
23 J2 = J2- 3
22继续
我在旧项目中看到过,我不知道这个IF如何用数字(标签)表示。
这是 arithmetic if
语句。改编自FORTRAN 77规范(重点介绍):
算术
IF
语句的形式为:
IF(e)s1,s2,s2
其中:
e
是一个整数,实数或双精度表达式
s1
,s2
和s3
都是出现在同一个程序中的可执行语句的语句标签m单位作为算术IF
语句。相同的语句标签可能会在同一个算法IF
语句中出现多次。
执行算术
IF
语句会导致评估表达式e
,然后传递控制权。 以s1
,s2
或s3 $ c $接下来执行c>,因为
e
的值分别小于零,等于零或大于零。
对于你问题中的例子,从上面的最后一句话来看,
J1-3<如果
J1-3 = 0
语句20也将被执行
J1-3> 0
语句21将被执行
编辑:现代化和更多如果(J1-3> 0)J1 = J1-3
,则可读的方式如下:
if如果(J2-3> 0)J2 = J2 - 3
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.
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
, 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.
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
这篇关于带有数字/标签的Fortran IF语句而不是其他语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!