gerador de python em while loop

from itertools import takewhile

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