If...Else
Do something based on a boolean expression.
Syntax
if (booleanExpression1) {
// code to be executed if true
}
else if(booleanExpression2) {
// booleanExpression1 is false and booleanExpression2 is true
}
else if (booleanExpression3) {
// booleanExpression1 and 2 are false and booleanExpression3 is true
}
. // "else if" statements are optional and you can have infinitely many
.
else {
// code to execute if all test expressions are false (optional)
}if booleanExpression1:
# statement(s)
elif booleanExpression2:
# statement(s)
elif booleanExpression3:
# statement(s)
else:
# statement(s)
# Note: "elif" and "else" statements are optionalExample 1: If
Example 2: If...else
Example 3: If...else if
Example 4: If...else if...else
Example 5: With Numbers
Important Notes
Last updated
