无需括号的嵌套IF-Else的工作 [英] Working of Nested IF-Else Without the Braces

查看:90
本文介绍了无需括号的嵌套IF-Else的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下嵌套大括号 没有的嵌套If-Else语句的工作。

我想了解为什么以下程序没有给我任何输出。

我已经检查了所有4种可能性。

(Outer-If,Inner-If)::( True,True),(True,False),(False ,True),(False,False)。

我正在使用CodeBlocks在Windows上使用gcc编译器进行编辑。

Can someone please explain me the working of Nested If-Else Statements written WITHOUT the Curly Braces.
I want to understand why Below Programme isn't giving me any output.
I've checked for all the 4 possibilities.
(Outer-If, Inner-If)::(True, True),(True, False),(False, True),(False, False).
I'm editing with CodeBlocks,using gcc compiler on Windows.

int main() 
{
  int n=0,m=0;
  if ( n > 0 )
       if ( m > 0 ) 
         printf("Inner-If Condition satisfied.");
  else 
     printf("Inner-If condition not satisfied. ");
  return 0;
}

谢谢。

推荐答案

-后面的语句周围有花括号。那么在您的情况下:

They work as-if there was a curly brace around the following statement. In your case then:

if ( n = 0 ){ // ToDo - did you mean `==`, `n = 0` is `0`.
    if ( m = 0 ){ // ToDo - ditto.
        printf("True");
    } else {
        printf("False");
    }
}

在您的情况下,我认为困惑来自您的使用 = 而不是 ==

In your case I think the bewilderment stems from your using = rather than ==.

这篇关于无需括号的嵌套IF-Else的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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