The while statement

while loopstatement

The while statement is used for repeated execution as long as a condition is true:

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

This repeatedly tests the condition and, if it is true, executes the first suite; if the condition 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. else

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 condition. break continue