if和if else之间的区别if if else if? [英] Difference between if and if else and if else if?

查看:139
本文介绍了if和if else之间的区别if 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, if 5 is equal to 5, then the code inside the ¬
if block is executed.

if (5 == 4)
{
// some code
}
else
{
// some other code
}


In this case, if 5 is equal to 4, then the code inside the if block is executed.
If 5 is NOT equal to 4, then the code inside the else block is executed.

if (5 == 4)
{
// some code
}
else if (5 == 6)
{
// some other code
}


In this case, if 5 is equal to 4, then the code inside the
if block is executed.
If 5 is not equal to 4, then the code in the else if block will only get executed if 5 is equal to 6.

Hope this helps.


There isn't one: else if in c# is just an elseclause that contains an if 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屋!

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