while semantics

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu Mar 13 21:56:33 EST 2003


> From: David Bear [mailto:david.bear at asu.edu]
> 
> Grant Edwards wrote:
> 
> > No.  conditionX will only be checked once per "outer loop".  If
> > you're in one of the inner loops, you stay there until that
> > loop's condition is false.
> 
> What about
> 
> while (condition):
>         do stuff
>         do more stuff
>         condition becomes true
>         do even more stuff
> 
> Will while terminate AS SOON as condition is true, or will it 
> evaluate all 
> statements in the block?

Read the above statement by Grant and you should be able to work it out. If you have problems, try running it and see.

a = 0
b = 1
c = 2

while a < 1:
    b = 2
    a = 1
    c = 3

Tim Delaney





More information about the Python-list mailing list