作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
中断嵌套循环时会发生什么?
假设如下代码:
for(int x = 0; x < 10; x++)
{
do {
if(x == 4)
break;
x++;
} while(x != 1);
}
遇到break语句,for循环还是do while循环,哪个循环会退出?
最佳答案
break
总是中断最内层的循环。
6.8.6.3
A break statement terminates execution of the smallest enclosing switch or iteration statement.
如果你想跳出这两个循环,在 for
之后使用一个标签并用 goto 跳转。 .
关于c - 打入 do while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12217014/
中断嵌套循环时会发生什么? 假设如下代码: for(int x = 0; x < 10; x++) { do { if(x == 4) break;
我是一名优秀的程序员,十分优秀!