2016-04-19 43 views
-5

C语言中级联if语句和嵌套if语句之间的区别是什么?C编程语言中级联和嵌套if语句

+0

请提供更多信息。 – Olaf

+0

'级联if语句'我在'C#'中读到类似这样的内容,但不是'C' – Michi

+0

级联检查1(真)或0(假)某些数量的变体? –

回答

2

级联:

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为真或假。

+0

我不认为是真的,级联是== >> if { } else else {} else if {} ....... {} else {}'[see here](http://palmsforcs1.pbworks.com/w/page/13844712​​/CascadingIf) – Michi

+0

^你是什么指称为if-else-if阶梯。 – CinCout

+0

是的,也知道是Cascading If Statements – Michi