- If you want to execute a statement only when an expression
produces a value other than
0, then use an
if statement:
if (Boolean expression) statement
- If you want to execute one statement when an expression
evaluates to any integer other than
0, and another when the
expression evaluates to 0, then use an if-else
statement:
if (Boolean expression)
if-true statement
else
if-false statement
- If you want to execute a group of statements in an
if or
if-else statement, then use braces to combine those
statements into a single compound statement.
- If you want to use nested
if-else statements, then use
braces to clarify your grouping intention.
- If you want the value of an expression to be the value of one of two
embedded expressions,
and you want the choice to be determined by the value of a
Boolean expression,
then instantiate the following pattern:
Boolean expression
?
if-true expression : if-false expression