having problems with a multi-conditional while statement

bowman.joseph at gmail.com bowman.joseph at gmail.com
Tue Jan 6 19:18:10 EST 2009


Hi,

I'm trying to write a multi-conditional while statement, and am having
problems. I've broken it down to this simple demo.

#!/usr/bin/python2.5

condition1 = False
condition2 = False

while not condition1 and not condition2:
    print 'conditions met'
    if condition1:
        condition2 = True
    condition1 = True


As I understand it, this should print 'conditions met' twice, however,
it only prints it once. It seems that once condition1 is made true,
the whole thing evaluates as true and stops the while loop.

I've also tried to set the while condition the following ways also,
and had the same problem

while (not condition1 and not condition2):
while (not condition1) and (not condition2):
while condition1 != True and condition2 != True:
while (condition1 != True and condition2 != True):
while (condition1 != True) and (condition2 != True):

Can someone lend me a hand in understanding this?




More information about the Python-list mailing list