难道只为`for`,`while`,`做-whil​​e`,'开关'和`if`陈述`break`工作? [英] Does `break` work only for `for`, `while`, `do-while`, `switch' and for `if` statements?

查看:135
本文介绍了难道只为`for`,`while`,`做-whil​​e`,'开关'和`if`陈述`break`工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设,我有一个循环中如果语句:

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`,`做-whil​​e`,'开关'和`if`陈述`break`工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆