Is Fortran return statement obsolete?

穿精又带淫゛_ 提交于 2019-12-12 12:08:44

问题


I just want to know if the return statement in Fortran 2008 is obsolete, because it seems to be unnecessary to write it at the end of subroutines and functions.

Does it have some other utility?


回答1:


No, it is not obsolete.

It is used to exit a subroutine and a function. Whenever you want to exit in the middle of a subroutine, you use RETURN. For example, when some error happens or similar.

Using RETURN is an alternative to long if conditions like

if (no_error) then




   a lot of code




 end if

You just do

 if (error) return

 a lot of code



回答2:


As well as being able to complete execution of a function or subroutine at any point, rather than just before the end, the return statement may (currently) be used to give alternate return:

return 2

Alternate return is obsolete and soon to be deleted, but is something in Fortran 2008 that doesn't happen without return.




回答3:


It is not obsolete but it seems optional, as I have seem programs compile and run without it. (Using ifort)



来源:https://stackoverflow.com/questions/49802011/is-fortran-return-statement-obsolete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!