|
Original |
Translation |
|
7
|
if x < y < z: print(x); print(y); print(z)
|
|
|
8
|
|
|
|
9
|
Note that statements always end in a ``NEWLINE`` possibly followed by a ``DEDENT``. Also note that optional continuation clauses always begin with a keyword that cannot start a statement, thus there are no ambiguities (the 'dangling :keyword:`else`' problem is solved in Python by requiring nested :keyword:`if` statements to be indented).
|
|
|
10
|
The formatting of the grammar rules in the following sections places each clause on a separate line for clarity.
|
|
|
11
|
|
12
|
The :keyword:`if` statement is used for conditional execution:
|
|
|
13
|
It selects exactly one of the suites by evaluating the expressions one by one until one is found to be true (see section :ref:`booleans` for the definition of true and false); then that suite is executed (and no other part of the :keyword:`if` statement is executed or evaluated). If all expressions are false, the suite of the :keyword:`else` clause, if present, is executed.
|
|
|
14
|
The :keyword:`while` statement
|
|
|
15
|
The :keyword:`while` statement is used for repeated execution as long as an expression is true:
|
|
|
16
|
This repeatedly tests the expression and, if it is true, executes the first suite; if the expression is false (which may be the first time it is tested) the suite of the :keyword:`else` clause, if present, is executed and the loop terminates.
|
|