if...else语句的四种结构用法

总结一下if…else…其实也就四种

第一种:简单的if…语句

if (condition){  
  当条件为 true 时执行的代码
  }

第二种:简单的if…else…语句

  if (condition)
{
    当条件为 true 时执行的代码
}
else
{
    当条件不为 true 时执行的代码
}

第三种:嵌套式的if…else…语句

if (condition)
{
        if (condition){
                    当条件为 true 时执行的代码
        }
        else{
                    当条件不为 true 时执行的代码
                }
}
else(condition)
{
    当条件不为 true 时执行的代码
}

第四种:if…else if…else 语句

if (condition1)
{
    当条件 1true 时执行的代码
}
else if (condition2)
{
    当条件 2true 时执行的代码
}
else
{
  当条件 1 和 条件 2 都不为 true 时执行的代码
}

你可能感兴趣的:(if...else语句的四种结构用法)