if Statements

Python Java
Form:

if <Boolean expression>:
    <statement>
    …
    <statement>
elif <Boolean expression>:
    <statement>
    …
    <statement>

else:
    <statement>
    …
    <statement>

The statements in the consequent and each alternative are marked by indentation.

Form:

if (<Boolean expression>){
    <statement>
    …
    <statement>
}else if (<Boolean expression>){
    <statement>
    …
    <statement>

}else{
    <statement>
    …
    <statement>
}

The statements in the consequent and each alternative are marked by curly braces ({}).  When there is just one statement, the braces may be omitted.

Each Boolean expression is enclosed in parentheses.

© Ken Lambert. All rights reserved.