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

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

问题描述

使用 break 函数退出多个嵌套 for 循环是否合适?如果是这样,你会怎么做呢?

Is it proper to use the break function to exit several nested for loops? 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天全站免登陆