The if-else statements enable your program to selectively execute other statements, based on some criteria. The simplest version, the if statement, is shown below. The block governed by if (delimited with '{' and '}') is executed if the expression is true, otherwise the execution continues after the last '}'.
if (expressions)
{
statement(s)
}
If you want to execute other statements when the expression is false, you use the else statement.
if (expression)
{
statement(s) executed if expression is true
}
else
{
statement(s) executed if expression is false
}
Another statement, elseif, executes statements if an earlier if expression was false and it's own expression is true; elseif is used to form chains of conditions. If expression 1 is true, the if block executes and then the program jumps to the last '}' of the else block. Expression 2 will never be evaluated. If, however, expression 1 is false, expression 2 will be evaluated and the elseif-else will work as a regular if-else as shown above.