带内部 goto 的 Fortran do 循环
我有一个 Fortran77 代码片段,如下所示:
DO 1301 N=NMLK-2,2,-1
Some code...
IF(NB1(N).EQ.50) GOTO 1300
Some code...
IF(BS(N).EQ.0.0) GOTO 1301
some code...
GOTO 1301
1300 NW(M)=NB1(N)
Some code...
1301 CONTINUE
当遇到 GOTO 1301 语句时,它会跳转到循环的下一次迭代还是退出循环? 据我了解 return 关键字什么都不做,所以我假设这只会退出循环并继续从标签 1301 开始执行代码,这是正确的吗?
我正在将其翻译为 C#,并且想知道这是否等效:
for (N = NMLK; N >= 2; N--)
{
Some code...
if (NB1[N] == 50)
goto l1300;
Some code...
if (BS[N] == 0)
return;
Some code...
return;
l1300:
NW[M] = NB1[N];
Some code...
}
或者我是否应该使用“继续”而不是“返回”?
I have a Fortran77 snippet that looks like this:
DO 1301 N=NMLK-2,2,-1
Some code...
IF(NB1(N).EQ.50) GOTO 1300
Some code...
IF(BS(N).EQ.0.0) GOTO 1301
some code...
GOTO 1301
1300 NW(M)=NB1(N)
Some code...
1301 CONTINUE
When this hits the GOTO 1301 statement, does this jump to the next iteration of the loop or does it exit the loop?
As far as I understand the return keyword does nothing, so I assume that this will just exit the loop and continue code execution from label 1301, is that correct?
I am translating this to C# and am wondering if this is equivalent:
for (N = NMLK; N >= 2; N--)
{
Some code...
if (NB1[N] == 50)
goto l1300;
Some code...
if (BS[N] == 0)
return;
Some code...
return;
l1300:
NW[M] = NB1[N];
Some code...
}
or if I should have "continue" instead of "return"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,
GOTO 1301
语句使程序跳转到下一个迭代。DO label
、label CONTINUE
是编写更现代的DO ENDDO
块的过时方法。在这种情况下,循环将迭代 DO 行上指定的变量,并且label CONTINUE
行充当“ENDDO
”占位符。Yes, the
GOTO 1301
statement makes the program jump to next iteration.The
DO label
,label CONTINUE
is an obsolete way to write a more contemporaryDO ENDDO
block. In this case the loop will iterate over variables specified on the DO line, andlabel CONTINUE
line serves as an "ENDDO
" placeholder.