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

    Join Date
    Dec 2004
    Posts
    2
    Rep Power
    0

    For in range question?


    Hi,

    I have a qeustion about a
    for someCounter in range(0, len(someString) ):

    Is there anyway i can higher up "someCounter" inside the for loop,
    becuase I need 2 skip 1 count ad a surten posision, but these posison are random. So I can not excluted them from the for loop.
    As far as I know there is no way 2 build a for without useing a range or xrang ?????.

    thnx for your time,
    Erik
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Use a while loop then.
    Code:
    someCounter = 0
    nMax = len(someString)
    while someCounter < nMax:
        # Do something here
        if something():
            someCounter += 2
        else:
            someCounter += 1
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Another little work around, but we could probably provide a better solution if we knew exactly what your trying to do.

    Code:
    >>> for someCounter in range(0, 9):
    	if someCounter == 5:
    		continue
    	print someCounter
    
    	
    0
    1
    2
    3
    4
    6
    7
    8
    >>> for someCounter in range(0, 9):
    	if someCounter < 5:
    		continue
    	print someCounter
    
    	
    5
    6
    7
    8
    >>>
    This simply skips to the next number until it find a number that you want to do something with.

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    2
    Rep Power
    0
    I think, the only why would be the while loop.
    Aldo its a shame i have do use multipe statmens, for simple char skipping in a string..

    thnx for your time.
    Erik
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Could you not remove the characters from the string first?

    Code:
    line = "test abcde"
    line = line.replace("e", "")
    
    for char in line:
        print char

IMN logo majestic logo threadwatch logo seochat tools logo