mailing list wrote: > Hi all, > > I should know this, but it seems to elude me at present. > > I have a loop which is looping through a line of chars by index. > > So, one of these - > > for i in range(len(line)): > > > Now, question is, is there a simple way to 'fast forward' index i? > > At the moment, I'm doing it like this - > > changeIndex = None > al = len(line) > for i in range(al): > > if changeIndex and (i < changeIndex): > continue > > if line[i] == "{": > nextRightBracket = line.find("}",i) > #other stuff happens > changeIndex = nextRightBracket + 1
I would do this with a while loop and an explicit index counter: al = len(line) i = 0 while i < al: if line[i] == "{": nextRightBracket = line.find("}",i) #other stuff happens i = nextRightBracket + 1 else: i += 1 You could also make a custom iterator that you could set but it doesn't seem worth the trouble. If you just had to skip one or two values I would make an explicit iterator and call next() on it, but to advance an arbitrary amount that is awkward. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor