【问题标题】:Cascaded and nested if statements in C programming languageC 编程语言中的级联和嵌套 if 语句
【发布时间】:2016-04-19 17:00:46
【问题描述】:

C语言中级联if语句和嵌套if语句有什么区别?

【问题讨论】:

  • 请提供更多信息。
  • cascaded if statements 我在C# 中读到过类似的内容,但C 没有
  • 是否级联检查 1(true) 或 0(false) 一些变体?
  • 第一个或第二个或第三个 itc,并在放入此 if 语句的语句之间嵌套检查第一个 if 语句是否为真
  • 顺便说一句,我正在读 King C 的书

标签: c if-statement


【解决方案1】:

级联:

if (condition1)
{
    // do one thing
}
if (condition2)
{
    // do other thing
}

这里,如果condition1 为真,one thing 将完成。同样,如果condition2 为真,other thing 也将完成。

嵌套:

if (condition1)
{
    // do one thing
    if (condition2)
    {
        // do other thing
    }
}

这里,如果condition1 为真,one thing 将完成。而且,如果condition2也是为真,other thing 也将成立。

请注意,在后一种情况下,两个条件都必须为真,other thing 才会发生。在第一种情况下,如果condition2 为真,则other thing 发生,而不管condition1 是真还是假。

【讨论】:

  • 我认为不是真的,级联是==>> if{}else if{}else if{}.......{}else{} See here
  • ^你所说的叫做 if-else-if 阶梯。
  • 是的,也称为级联 If 语句
  • @Michi:可能是这样,但从语法上讲,这也是一个嵌套的。只是一种不同的格式来避免失控的缩进。
  • 就我的英语知识而言,级联if 只是一系列if 语句。
猜你喜欢
  • 2017-03-24
  • 2012-03-25
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
  • 2018-10-26
  • 2021-01-10
  • 1970-01-01
相关资源
最近更新 更多