Steven D'Aprano wrote: >> about range()/xrange(): what if you want to traslate this c-loop? for >> (int i=1; i<50; i*=2) > > That's a completely different question, so of course it has a completely > different answer. Here is one way:
... various options snipped ... and another way for use when you have more than one loop following this pattern: def powerrange(base, start=0, limit=0): value = base**start while value < limit: yield value value *= base for i in powerrange(2,0,50): dosomething(i) Putting the question the other way round: how would you move the control logic out of the loop in C? -- http://mail.python.org/mailman/listinfo/python-list