难道只为`for`,`while`,`做-while`,'开关'和`if`陈述`break`工作? [英] Does `break` work only for `for`, `while`, `do-while`, `switch' and for `if` statements?
问题描述
假设,我有一个为
循环中如果
语句:
Suppose, I have a if
statement inside a for
loop:
for( ; ; )
{
if( )
{
printf(" inside if");
break;
}//if
printf("inside for");
}//for
现在,将在破
语句会导致编译出来的为
循环还是会只来是否的的身体曾经在
如果
成为满意?条件
Now, will the break
statement cause the compiler to come out of the for
loop or will it only come out of the body of if
once the condition in the if
becomes satisfied?
推荐答案
的破
语句跳出了的最近的封闭的循环或开关语句的
The break
statement breaks out of the nearest enclosing loop or switch statement.
破
没有打出去的如果
语句,但最近循环
或开关
包含如果
语句。其原因不是如果
语句的爆发是因为它通常用来决定是否要打出来的循环
。
break
does not break out of an if
statement, but the nearest loop
or switch
that contains that if
statement. The reason for not breaking out of an if
statement is because it is commonly used to decide whether you want to break out of the loop
.
有趣的是,电话交换机不守规矩,因为发明了Ç公司提出正是这个bug 。他们想打破一个如果
语句,他们忘了,它会跳出整个为
语句
Interestingly, a telephone switch misbehaved because the company that invented C made exactly this bug. They wanted to break out of an if
statement and they forgot that it would break out of the entire for
statement.
这篇关于难道只为`for`,`while`,`做-while`,'开关'和`if`陈述`break`工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!