return在if没有括号情况下,不管是跟在if()后面还是下一行,都是当if为true的时候,返回,不执行下面Debug,反之为false时,则执行Debug。
int a = 5;
if (a > 7) //1.return;
//2.return;
Debug.Log("A>0");
if在有括号情况下,才是通常的if为true,输出Debug,为false 就直接返回。
bool isFly; /// 官方默认是等于false。
if(isFly)只有当isFly为true执行{}里的语句
int a = 1;
if (a > 0)
{
Debug.Log("A>0");
}
else
{
return;
}
//这边如果不写else,直接下面直接跟return,会报错
Debug.Log("A=1");
① 、if加上{}且if为true
int a = 3;
if (a > 1)
{
Debug.Log("A>0");
Debug.Log("A=0");
Debug.Log("A<0");
}
Debug.Log("返回");
///输出A>0,A=0,A<0,返回
② 、if加上{}且if为false
int a = 1;
if (a > 1)
{
Debug.Log("A>0");
Debug.Log("A=0");
Debug.Log("A<0");
}
Debug.Log("返回");
///输出返回
③、if不加{},且if为flase
int a = 1;
if (a > 1)
Debug.Log("A>0");
Debug.Log("A=0");
Debug.Log("A<0");
Debug.Log("返回");
///输出A=0,A<0,返回
④、if不加{},且if为true
int a = 1;
if (a > 0)
Debug.Log("A>0");
Debug.Log("A=0");
Debug.Log("A<0");
Debug.Log("返回");
///输出A>0,A=0,A<0,返回