2.12. while LoopThe standard while conditional loop statement is similar to the if. Again, as with every code sub-block, indentation (and dedentation) are used to delimit blocks of code as well as to indicate which block of code statements belong to: while expression: while_suite The statement while_suite is executed continuously in a loop until the expression becomes zero or false; execution then continues on the first succeeding statement. Like if statements, parentheses are not required with Python while statements. >>> counter = 0 >>> while counter < 3: ... print 'loop #%d' % (counter) ... counter += 1 loop #0 loop #1 loop #2 Loops such as while and for (see below) are covered in the loops section of Chapter 8. |