打破嵌套循环 [英] Break nested loops
本文介绍了打破嵌套循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何打破主循环,当我有嵌套循环?
例如*:
Can someone tell me how to break the main loop when I have nested loops?
Example*:
/*Main loop*/
for(int y = 0; y < 100; y+=10)
{
/*Sub loop*/
for (int x = 0; x < 100; x += 10)
{
if(x == 60)
{
//Break the main loop
}
}
}
*此code什么也不做,这只是一个例子
*This code do nothing, it's just an example
我应该把在打破主循环的评论的地方吗?在java中有标签,我可以打破(当我设置一个标签,名为主循环我可以写主循环打破主循环,这将是有效的),但我能做些什么位置
What should I put in the place of the "Break main loop" comment? In java there are labels which I can break (when i set a label to the main loop named "MainLoop" I can write "break MainLoop;" and it will be valid), but what can I do here?
谢谢指教!
推荐答案
GOTO
!
我不明白为什么人们总是说 GOTO
被认为是有害的。很好用的,这是非常强大的,这也是这种情况。
I don't understand why people always say that goto
is considered "harmful". Well used, it is very powerful, and this is such a case.
这篇关于打破嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文