tumblr tracker

ElseIf

Parent Previous Next

ElseIf keyword


Checks another condition after the initial If condition failed and if true executes the associated commands. Must follow after an If keyword or another ElseIf keyword.


If (condition is true) {

//commands to execute

}

ElseIf (another condition is true) {

//commands to execute

}


The brackets () enclosing the condition and the curly brackets {} enclosing the commands to execute are required. The curly bracket can also start on a line of its own.



Example


$now = DateTime.GetCurrentDateTime();
$month = DateTime.GetMonth($now);

If ($month > 3 and $month <= 6)
{
   MessageBox.ShowInfo("We are in the second quartal of the year.");
}

ElseIf ($month > 6 and $month <= 9)
{
   MessageBox.ShowInfo("We are in the third quartal of the year.");
}