osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The "loop and a half"


Given the prevalence of the loop and a half idea in python I wonder why we don't 
have a "do" or "loop" statement to start loops without a test.


> C:\Python27\Lib>grep "while True" *.py | wc -l
>      99
> 
> C:\Python27\Lib>grep "while 1" *.py | wc -l
>     117

> C:\Python36\Lib>grep "while True" *.py | wc -l
>     131
> 
> C:\Python36\Lib>grep "while 1" *.py | wc -l
>      44

How much does the while True actually cost compared to nothing?
-- 
Robin Becker