Fortran 90 及更高版本强烈建议不要使用goto语句。
但是,我仍然觉得必须在以下两种情况下使用它:
情况 1 -- 指示重新输入输入值,例如
program reenter
10 print*,'Enter a positive number'
read*, n
if (n < 0) then
print*,'The number is negative!'
goto 10
end if
print*,'Root of the given number',sqrt(float(n))
stop
end program reenter
Run Code Online (Sandbox Code Playgroud)
案例 2 —— 注释程序的一个大的连续部分(相当于/* ... */C 中的)。例如。
print*,'This is to printed'
goto 50
print*,'Blah'
print*,'Blah Blah'
print*,'Blah Blah Blah'
50 continue
print*,'Blahs not printed'
Run Code Online (Sandbox Code Playgroud)
goto在 Fortran 90 中的上述两种情况下,如何摆脱 using语句并使用一些替代方案?