- If you want to execute a statement only when a Boolean expression produces
true, then use an if statement:
if (Boolean expression) statement
- If you want to execute one statement when an expression evaluates to
true, and another when the expression evaluates to false,
then use an ifelse statement:
if (Boolean expression)
if-true statement
else
if-false statement
- If you want to execute a group of statements in an
if or
ifelse statement, then use braces to combine those statements
into a single block.
- If you want to use nested
ifelse 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