通过任何返回条件的限定,循环会中断 groovy
当循环符合 return 语句时是否终止?即使值为空?
Do the loop terminates when it qualifies the return statement? even when value is null?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题太模糊,无法得到任何确定的回答。但是,如果我冒险猜测,我敢打赌您指的是“.each”循环中的控制语句?
如果是这样,简短的回答是:不,return(或break)不会终止循环。唯一的方法是在循环中抛出异常:
但是,这完全是令人厌恶的。请改用 for 或 while 循环。
另请参阅:
如果我偏离主题,也许您可以发布一些代码来举例说明您的主题?
Your question is too vague to be answered with any kind of certainty. Were I to hazard a guess, however, I'd bet you're referring to control statements within a '.each' loop?
If so, the short answer is: No, return (or break) does not terminate the loop. The only way to do so is via throwing an exception within the loop à la:
But, this is a total abomination. Use a for or while loop instead.
See also: returning from closure
If I'm off the mark, perhaps you could post some code exemplifying your topic?