Terry Reedy <tjre...@udel.edu>:

> On 4/6/2016 10:14 AM, Marko Rauhamaa wrote:
>
>> Seriously, Python wouldn't be, couldn't be Turing-complete without
>> "while" (mainly because it doesn't support tail-recursion
>> elimination).
>>
>> Now, if Python had an unlimited range() iterator/iterable, you could
>> use a "for" statement to emulate "while".
>
> For practical purposes, this equals 'while True: pass'
>
> for i in itertools.count: pass
>
> This is equivalent, regardless of memory.
>
> class whiletrue:
>     def __iter__(self): return self
>     def __next__(self): return None
>
> for none in whiletrue(): pass

By George, she's got it!

    i = 0
    for _ in itertools.count():
        if i >= 10:
            break
        print(i)
        i += 1

That is, assuming "break" is allowed.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to