Python 3 order of testing undetermined

Posted by user578598 on Stack Overflow See other posts from Stack Overflow or by user578598
Published on 2011-01-17T13:55:56Z Indexed on 2011/01/17 15:53 UTC
Read the original article Hit count: 171

Filed under:
|
|
|
string='a'
p=0
while (p <len(string)) & (string[p]!='c') :
                    p +=1

print ('the end but the  process  already died ')
       while (p <1) & (string[p]!='c') :
IndexError: string index out of range

I want to test a condition up to the end of a string (example string length=1) why are both parts of the and executed is the condition is already false! as long as p < len(string). the second part does not even need executing. if it does a lot of performance can be lost

© Stack Overflow or respective owner

Related posts about python

Related posts about comparison