标签而不是另一个语句的

标签而不是另一个语句的

本文介绍了带有数字/标签而不是另一个语句的 Fortran IF 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个 Fortran 代码是什么意思:

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

我在旧项目中见过,我不知道这个带有数字(标签)的 IF 是什么意思.

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

推荐答案

这是一个 算术 if 语句 来自 FORTRAN 77.改编自 FORTRAN 77 规范(强调我的):

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

算术IF语句的形式为:

IF (e) s1 , s2 , s2

  • 其中:e 是整数、实数或双精度表达式

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

s1s2s3 分别是出现在同一程序单元中的可执行语句的语句标签算术 IF 语句.同一个语句标签可能在同一个算术 IF 语句中出现多次.

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.

算术 IF 语句的执行导致表达式 e 的求值,然后是控制转移.s1s2s3 标识的语句接下来执行,因为 e 的值为分别小于零、等于零或大于零.

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,

  • 如果 J1-3 语句20将被执行
  • 如果 J1-3 = 0 语句 20 也会被执行
  • 如果 J1-3 >0将执行第21条语句
  • 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 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:43