假设以下代码:
for(int x = 0; x < 10; x++) { do { if(x == 4) break; x++; } while(x != 1); }
在遇到break语句,for循环或do while循环时,哪个循环将退出?
6.8.6.3 A break statement terminates execution of the smallest enclosing switch or iteration statement.
6.8.6.3
A break statement terminates execution of the smallest enclosing switch or iteration statement.
如果要打破两个循环,请在for之后使用标签并使用goto跳转.