generador de pitón en while loop

from itertools import takewhile

i = iter(range(10))
for x in takewhile({some logic}, i):
    # do stuff
Expert--;