我可以使用break退出多个嵌套的"for"循环吗? [英] Can I use break to exit multiple nested 'for' loops?

查看:375
本文介绍了我可以使用break退出多个嵌套的"for"循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用break函数退出几个嵌套的for循环?

Is it possible to use the break function to exit several nested for loops?

如果是这样,您将如何去做?您还可以控制break退出多少个循环吗?

If so, how would you go about doing this? Can you also control how many loops the break exits?

推荐答案

AFAIK,C ++不像Java和其他语言一样支持命名循环.您可以使用goto,或创建您使用的标志值.在每个循环结束时,检查标志值.如果将其设置为true,则可以退出该迭代.

AFAIK, C++ doesn't support naming loops, like Java and other languages do. You can use a goto, or create a flag value that you use. At the end of each loop check the flag value. If it is set to true, then you can break out of that iteration.

这篇关于我可以使用break退出多个嵌套的"for"循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆