我有一个长的条件语句来决定是否退出我在几个地方使用的do while循环。
if (long_class_name <= something + 0.5 .and. &
long_class_name >= something - 0.5 .and. &
long_class_name <= some_other_thing + 0.5 .and. &
long_class_name >= some_other_thing - 0.5 .and. &
yet_another_thing == -999.0) exit是否有方法通过Fortran中的子例程或函数返回exit语句,例如:
call check_for_exit最好是,而不是必须添加变量等(例如,从函数返回一个逻辑,然后对其执行一个简单的if ):
exit_now = check_exit()
if (exit_now == .true.) exit发布于 2014-04-10 13:29:16
为什么不像在示例中那样简单地使用逻辑函数并直接测试它(没有附加变量):
if ( check_exit() ) exit或者,如果您想使用整数,例如负数表示错误,而正整数表示警告:
if ( complicated_check() > 0 ) then
print *, 'WARNING'
elseif( complicated_check() < 0 ) then
exit
endif虽然没有辅助变量,这开始变得低效;-)
发布于 2014-04-10 20:00:51
如果您想处理多个返回值,假设f90+可以使用select case来避免辅助变量(或者两次调用该函数)
select case ( complicated_check() )
case (1:)
print*,'Warning'
case (:-1)
exit
end selecthttps://stackoverflow.com/questions/22988559
复制相似问题