So, I got two different results by switching the positions of the conditions in an if statement.
Let's say we have an array of length 5 and i = 4 then in this statement,
if (A[i+1] == 0 or i == len(A)-1 ):
I get an index error, "IndexError: list index out of range"
But, if I switch the conditions and make them like this,
if (i == len(A)-1 or A[i+1] == 0 ):
I get the proper expected result and the program runs till the end.
Does the position of the conditional statements in if statement matter in a program ?
Aucun commentaire:
Enregistrer un commentaire