Executes block of code repeatedly while the specified condition is True.
- while condition:
- Any expression that has a Boolean value.
- Optional. Indicates block of code executed when loop terminates without calling break statement.
- Block of code to be executed.
The while statement provides an iterative condition based loop. The suite is executed repeatedly as long as expression is True. The test on expression takes place before each execution of statement.
>>> i = 0 >>> while i < 3: ... print i ... i = i + 1 ... 0 1 2