The else keyword is used to provide an alternative clause to an if statement. If the expression defined by the if statement evaluates to false, then control transfers to the first statement following the else keyword. If the expression defined by the if statement evaluates to true, then control transfers to the first statement following the if keyword.
Note that if/else conditional testing is a frequent source of program bugs. Consider the following example of a poorly formatted if/else condition:
if ( numPrints < 1000 )
if ( paperFeed == fullTray )
{
printPaperCopy( );
showStatus( );
paperFeed--;
}
else
suspendPrintJob( ) // Bad indenting!;
In the example shown above, the beginning of the else statement block is formatted to fall into the same column as the outermost if statement, even though it's proper association is with the closest if statement. Problems of this nature can be easily overlooked unfortunately, and it is up to the programmer to use good formatting to illustrate the logical intent of the code.