if和if else之间的区别if if else if? [英] Difference between if and if else and if else if?
问题描述
if和if之间的区别if if if?
if ( 5 == 5 )
{
// 某些代码
}
In在这种情况下,如果5
等于5
,那么¬
内的代码如果执行了
块。
如果( 5 == 4 )
{
// 部分代码
}
其他
{
// 其他一些代码
}
在这种情况下,如果5
等于4
,那么代码在中,如果
块是执行ted。
如果5
不等于4
,那么其他内部的代码块执行。
if ( 5 == 4 )
{
// 某些代码
}
其他 如果( 5 == 6 )
{
// 其他一些代码
}
在这种情况下,如果5
等于4
,然后是
如果执行
块。
如果5
不等于4
,那么else中的代码如果
块只会在5
等于<$时执行c $ c> 6 。
希望这有帮助。
否则c#中的
只是一个包含<$ c $的 else
子句c> if 声明:
如果(a)
{
}
其他 如果(b)
{
}
其他
{
}
实际上与以下内容相同:
如果(a)
{
}
其他
{
如果(b)
{
}
< span class =code-keyword> else
{
}
}
但是第一个版本更容易阅读。
Difference between if and if else and if else if?
if (5 == 5) { // some code }
In this case, if5
is equal to5
, then the code inside the ¬
if
block is executed.
if (5 == 4) { // some code } else { // some other code }
In this case, if5
is equal to4
, then the code inside theif
block is executed.
If5
is NOT equal to4
, then the code inside the else block is executed.
if (5 == 4) { // some code } else if (5 == 6) { // some other code }
In this case, if5
is equal to4
, then the code inside the
if
block is executed.
If5
is not equal to4
, then the code in theelse if
block will only get executed if5
is equal to6
.
Hope this helps.
There isn't one:else if
in c# is just anelse
clause that contains anif
statement:
if (a) { } else if (b) { } else { }Is actually the same as:
if (a) { } else { if (b) { } else { } }But the first version is easier to read.
这篇关于if和if else之间的区别if if else if?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!