1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] how to use iterator in while loop statement in python

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    Is it possible to use a generator or iterator in a while loop in Python? For example, something like:

    i = iter(range(10))
    while next(i):
    # your code


    The point of this would be to build iteration into the while loop statement, making it similar to a for loop, with the difference being that you can now additional logic into the while statement:

    i = iter(range(10))
    while next(i) and {some other logic}:
    # your code


    It then becomes a nice for loop/while loop hybrid.

    Does anyone know how to do this?

    Continue reading...

Compartilhe esta Página