View Single Post
Join Date: Dec 2006
Posts: 977
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 273
woooee woooee is offline Offline
Posting Shark

Re: Absurd Loop Problem

 
0
  #2
Nov 20th, 2008
I would suggest the following print statements to clarify things.
  1. print "length of self.__fields =", fieldlength
  2. for counter1 in range(fieldlength):
  3. if self.__fields[counter1] == field:
  4. print "counter1 == field"
  5. for counter2 in range(rowlength):
  6. #print self.__rows[counter2][counter1]
  7. if self.__rows[counter2][counter1] == value:
  8. return1 = counter2
  9. matchcount = matchcount + 1
  10. print "The Match count is INSIDE THE LOOP: " + str(matchcount)
  11. ## counter2 = counter2 + 1 Has no effect
  12. else:
  13. print "counter1 & field NOT equal"
  14. ## counter1 = counter1 + 1 ## this statement does nothing
Note that the last statement is commented because it has no effect. Run the following code to see for yourself. This is because the statement "for ctr in range(0, 10)" generates a list [0, 1, 2...9] and iterates over this list so you increment the current value when incrementing the counter but don't change the list so there is no effect on the for() loop.
  1. for ctr in range(0, 10):
  2. print "loop's counter =", ctr
  3. ctr += 5
  4. print " ", ctr, "= incremented but doesn't have any effect"
Reply With Quote