关于嵌套是否的问题 [英] question about nested if

查看:93
本文介绍了关于嵌套是否的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嵌套if语句为的语法

Syntax of nested if statement is

if(Condition-1)
{
    if(condition-2)
    {
        statement-2;
    }
    Statement3;
}




我想知道如果条件1为假,编译器是否进入条件2?如果condition-1为false,它会做什么?




i want to know that if condition 1 is false Compiler goes to ckeck condition-2 or not? if condition-1 is false what it do?

推荐答案

仅在断言了条件1的情况下,才会评估条件2.

如果条件1为假,则什么都不会发生.
条件2将不会被评估,语句3也将不会被执行.

如果条件1为True,则将评估条件2;如果条件为false,则仅将执行语句3,否则将同时执行两个语句(2和3).

希望对您有帮助
Condition 2 will only be evaluated if Condition 1 asserted.

If Condition 1 is false, then nothing will happen.
Condition 2 won''t be evaluated and Statement 3 won''t be executed neither.

If Condition 1 is True then Condition 2 will be evaluated, if false then only Statement 3 will be executed, otherwise both Statements (2 and 3) will be executed.

Hope it helps


您应该学习使用调试器并购买一本不错的C ++书.您可以在if后面加上else语句,如

如果(conditiond2)
{
statement2
}
其他
{
statement3
}

如果您不这样做,那么语句3将始终运行,因为您要这样做.

另外,您嵌套了第二个条件,从而告诉程序仅在第一个条件成功的情况下才对其进行检查.如果要始终都选中第二个检出项,则将其放在第一个检查项上.
You should learn to use a debugger and buy a good C++ book. You can put an else statement after an if, as in

if (conditiond2)
{
statement2
}
else
{
statement3
}

if you don''t do that, then statement 3 will always run, because you''re asking it to.

In addition, you nested the second condition, thus telling the program to only check it if the first succeeds. Put the second check out side the first check, if you want both to always be checked.


否,因为仅当condition-1为if语句>
No, because the second if statement only gets looked at if condition-1 is TRUE


这篇关于关于嵌套是否的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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