Fortran 90和更高版本強烈建議不要使用goto
聲明。我們是否可以在所有情況下確實避免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
情況2 - 若要註釋程序(相當於在/* ... */
C)的一個大的連續的部分。例如,
print*,'This is to printed'
goto 50
print*,'Blah'
print*,'Blah Blah'
print*,'Blah Blah Blah'
50 continue
print*,'Blahs not printed'
如何才能擺脫使用goto
聲明和使用上述兩種情況下,一些替代品的Fortran 90的?
要從理論角度回答標題問題:[Böhm-Jacopini定理](https://en.wikipedia.org/wiki/Structured_program_theorem) – 2014-08-29 11:37:24