Promoting Python
Marko Rauhamaa
marko at pacujo.net
Wed Apr 6 16:05:50 EDT 2016
Terry Reedy <tjreedy at 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
More information about the Python-list
mailing list