Choices
if()
and else
Use if
to specify a block of code to be executed, if a specified condition is true. Use else
to specify a block of code to be executed, if the same condition is false.
if (condition) true_action
if (condition) true_action else false_action
(Note braces are only needed for compound expressions)
if (test_expression) {
true_action
} else {
false_action
}
Can be expanded to more alternatives:
if (test_expression) {
true_action
} else if (other_test_expression) {
other_action
} else {
false_action
}