DAGDA SEARCH | Back to results | Support

7.2 The while statement

Source: https://docs.python.org/2.0/ref/while.html

Previous Page Up One Level Next Page Python Reference Manual Contents Index
Previous: 7.1 The if statement Up: 7. Compound statements Next: 7.3 The for statement


7.2 The while statement

The while statement is used for repeated execution as long as an expression is true:

while_stmt:     "while" expression ":" suite
               ["else" ":" suite]

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 else clause, if present, is executed and the loop terminates.

A break statement executed in the first suite terminates the loop without executing the else clause's suite. A continue statement executed in the first suite skips the rest of the suite and goes back to testing the expression.


Previous Page Up One Level Next Page Python Reference Manual Contents Index
Previous: 7.1 The if statement Up: 7. Compound statements Next: 7.3 The for statement


See About this document... for information on suggesting changes.