< BACKMake Note | BookmarkCONTINUE >
156135250194107072078175030179198180024228156016206217188240240204173120061003211102074073

while Loop

The 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 suite is executed continuously in a loop until the expression becomes zero or false; execution then continues on the first succeeding statement.

					
>>> counter = 0
>>> while counter < 5:
…       print 'loop #%d' % (counter)
…       counter = counter + 1

loop #0
loop #1
loop #2
loop #3
loop #4
loop #5

				

Loops such as while and for (see below) are covered in the loops section of Chapter 8.


Last updated on 9/14/2001
Core Python Programming, © 2002 Prentice Hall PTR

< BACKMake Note | BookmarkCONTINUE >

© 2002, O'Reilly & Associates, Inc.