java 进程不关闭,Java Return不退出方法(循环)

I'm working on a project for school where I have many nested loops in a method. I can verify that my code is reaching the "return true;" statement before a "return false;" using way too many System.out.println statements.

Is there any case where return does not immediately exit the method. In my code it reaches the "return true;", but then continues working through the method.

Thanks - first post, but long time student from other questions

EDIT: Show my code - This is for a UC Berkeley project so they aren't allowing us to post our full code. Here is the important parts.

There are no "try statements" in my code. This is the very end of my method which has a ton of loops (while & for) loops.

if (x == 7 && turn == 5){

System.out.println("TRUE RESULT");

return true;

}

nextVictory(turn, x, y, color,z);

alive = false;

}

}

}

}

System.out.println("FALSE RESULT");

return false;

}

I have print statement to verify where I'm at. Here are the results:

TRUE RESULT

FALSE RESULT

FALSE RESULT

FALSE RESULT

FALSE RESULT

解决方案

Is there any case where return does not immediately exit the method?

The only case that comes to mind is if the return statement were inside a try-finally block. The finally block would still get executed.

Another case that could exhibit similar behaviour is if your method is recursive. In that case, a return statement in a nested call would actually return to the caller. However, if the caller is the method itself, this could have the appearance of the method continuing to execute past the return.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值