gpt4 book ai didi

带有数字/标签的 Fortran IF 语句而不是另一个语句

转载 作者:行者123 更新时间:2023-12-02 10:26:24 33 4
gpt4 key购买 nike

这段 Fortran 代码的含义:

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

我在旧项目中见过,但我不知道这个带有数字(标签)的 IF 意味着什么。

最佳答案

这是一个arithmetic if statement来自 FORTRAN 77。改编自 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, 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.

对于您问题中的示例,上面最后一句中,

  • 如果J1-3 < 0语句20将被执行
  • 如果J1-3 = 0语句20也会被执行
  • 如果J1-3 > 0语句21将被执行

编辑:一种现代且更具可读性的编写方式是:

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

关于带有数字/标签的 Fortran IF 语句而不是另一个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11124855/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com