在循环中中断

sgu*_*pta 7 c loops nested-loops

在嵌套循环中打破时会发生什么?

假设以下代码:

for(int x = 0; x < 10; x++)
{
    do {
        if(x == 4)
            break;
        x++;
    } while(x != 1);
}
Run Code Online (Sandbox Code Playgroud)

遇到break语句,for循环或do while循环时哪个循环会退出?

cni*_*tar 8

break老是打断最里面的循环.

6.8.6.3

break语句终止执行最小的封闭开关或迭代语句.


如果你想要摆脱两个循环,在使用gotofor跳转并使用goto跳转.