if statementPurpose:
- To choose among alternate courses of action in a program.
Mechanics:
if (<condition>) {/* Java statements */
}
Example:
if (numA == numB) {/* Java statements */
}
Usage:
- <condition> is any expression that evaluates to
trueorfalse.
Restrictions:
- First <condition> is evaluated. When
<condition> evaluates to
true, the/* Java statements */are executed. When <condition> evaluates tofalse, execution continues with the statement after the conditional code. - If there is more than one statement in the if clause, then curly brackets must be used. If there is only one statement, the curly brackets are optional.
email suggestions to: cs015tas@cs.brown.edu
