#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Infinite loop with WHILE


    Hi,

    I am posting a snippet of my code:

    XsdModelList = self.Api.XsdModelList

    while(len(XsdModelList)>0):
    print XsdModelList.pop().getFileName()
    print len(XsdModelList)


    self.Api.XsdModelList is a list; when I run my code I am getting stuck in an infinite loop. can someone help what i am doing wrong?

    Thanx
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    3
    Could you not use a for loop instead

    Code:
    for item in XsdModelList:
        print item.getFileName()
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,904
    Rep Power
    481
    It's possible that the XsdModelList object has an unusual definition of its __len__ method.
    Code:
    class dumbList(list):
        def __len__(self): return 18
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0
    Hmm, I used some print statements to see whats happening, the len() function counts down like it should and then stops at 0, but strangely the loop does not exit
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by Quackajack
    Could you not use a for loop instead

    Code:
    for item in XsdModelList:
        print item.getFileName()
    Yup, thats the way I am using it right now, its just unusual that the loop didn't work the way I thought it should.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0
    You don't use a while loop for something like this


    Code:
    a = [1,2,3]
    for x in a:
      print x

IMN logo majestic logo threadwatch logo seochat tools logo