if/else and if/elseif

后端 未结 10 1861
傲寒
傲寒 2020-12-17 01:00

If I have a statement block like this:

if (/*condition here*/){ }
else{ }

or like this:

if (/*condition here*/)
else if (/         


        
10条回答
  •  春和景丽
    2020-12-17 01:43

    Situation a:

    if( condition )
    {
    }
    else
    {
    }
    

    When the condition in the above statement is false, then the statements in the else block will always be executed.

    Situation b:

    if( condition )
    {
    }
    else if( condition2 )
    {
    }
    else
    {
    }
    

    When 'condition' is false, then the statements in the else if block will only be executed when condition2 is true. The statements in the else block will be executed when condition2 is false.

提交回复
热议问题