fortran - Fortran - 跳转其他子程序
问题描述
我正在尝试在 Fortran 代码中跳转其他子程序。我使用了返回函数,但在某些情况下它不起作用。有什么办法可以跳转到其他子程序。我做了一个简单的例子来定义问题。如果条件在同一个子程序中,我可以使用goto 标签,但我需要跳转不同的子程序。如果条件正确(case = .True.),我不想计算那个子程序,所以我会跳过那个子程序,我会开始使用新数据。例如,如果i=3 and case=true
,程序不应在第三个循环中打印 a=8 并在子程序 abc 中跳转 do 循环。
----------------------------------------------
subroutine abc()
do i=1, 5
!if case is true, start to program from here.
call vector ()
end do
end subroutine
-------------------------------------
subroutine vector()
if (case = .True.)then
*****JUMP call vector in main program *****
print *,"skip and jump "
return
a= 8
print *, a
else
b= 9
print *, b
print *, "continue the process "
end if
end subroutine
------------------------------------------------
-----output should be-------
9
9
skip and jump
9
9
解决方案
推荐阅读
- python - 如何保持活力并执行telethon +烧瓶
- jquery - 为什么 jQuery-select2 自动对焦不起作用,我该如何解决?
- python - 对于熊猫数据框,使用枚举的循环运行次数超出预期
- ruby-on-rails - routes.rb 中的子域
- javascript - 使用 || 应用默认值 无需在 JS 中重新分配变量
- javascript - 如何在 Excel js 中追加数据?
- amazon-web-services - 如何从本地服务器访问 Private Api 网关
- node.js - 如何在 paypal api 中获得付款?
- spring-boot - JPA 使用特定的 LAZY 行获取主数据
- django-rest-framework - 了解`serializer.save(owner=request.user)`