我有一个遗留的fortran代码,有许多语句,如'goto 50'.我想知道goto的目标是全球还是本地.我的意思是,如果多个函数的目标为'50',那么goto会导致什么.
谢谢回答.
语句标签(例如,"50")必须在当前"范围单元"中定义,该范围基本上在此上下文中转换为goto调用所在的子例程/函数(或主程序,如果调用在主程序).
因此,例如,在下面的程序中,主程序和两个包含的子程序都有自己的标签50,并且gotos转到"他们的"第50行.
program testgotos
implicit none
goto 50
call second
50 call first
call second
contains
subroutine first
integer :: a = 10
goto 50
a = 20
50 print *,'First: a = ', a
end subroutine first
subroutine second
integer :: a = 20
goto 50
a = 40
50 print *,'Second: a = ', a
end subroutine second
end program testgotos
Run Code Online (Sandbox Code Playgroud)