tumblr tracker

Else

Parent Previous Next

Else keyword


Encloses a block of commands to execute after previous If and all ElseIf conditions failed.


If (condition is true) {

//commands to execute

}

ElseIf (another condition is true) {

//commands to execute

}

ElseIf (another condition is true) {

//commands to execute

}

Else {

//commands to execute

}  


The curly brackets {} 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.");
}

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

Else
{
   MessageBox.ShowInfo("We are in the first quartal of the year.");
}