| CHAPTER 14: Blocks and Statements |
Previous |
Java Language |
Index |
Next |
The if statement allows conditional execution of a statement or a conditional choice of two statements, executing one or the other but not both.
IfThenStatement: if ( Expression ) Statement IfThenElseStatement: if ( Expression ) StatementNoShortIf else Statement IfThenElseStatementNoShortIf: if ( Expression ) StatementNoShortIf else StatementNoShortIf
The Expression must have type boolean , or a compile-time error occurs.
An if -then statement is executed by first evaluating the Expression. If evaluation of the Expression completes abruptly for some reason, the if -then statement completes abruptly for the same reason. Otherwise, execution continues by making a choice based on the resulting value:
An if -then -else statement is executed by first evaluating the Expression. If evaluation of the Expression completes abruptly for some reason, then the if - then -else statement completes abruptly for the same reason. Otherwise, execution continues by making a choice based on the resulting value:
| © 1996 Sun Microsystems, Inc. All rights reserved. |