Looping [was Re: Python and the need for speed]

Terry Reedy tjreedy at udel.edu
Mon Apr 17 09:05:20 EDT 2017


On 4/17/2017 3:11 AM, Marko Rauhamaa wrote:
> Gregory Ewing <greg.ewing at canterbury.ac.nz>:
>
>> bartc wrote:
>>> Most of my loops start off as endless loops, until I can determine
>>> the actual terminating condition, and where it best goes.
>>
>> Interesting. My experience is quite different. Most of the loops I
>> write start off with me thinking "Now I want to do this for each
>> element of this collection", which maps straight to a Python for-loop.
>>
>> In the rare cases where I do use a while loop, usually I have a fairly
>> good idea what the terminating condition is going to be.
>
> Here's statistics from a medium-sized project of mine:
>
>    while True:            34
>    while <condition>:     39
>    for ... in ...:       158

As I posted previously, the ratio of for-loops in the stdlib is about 7 
to 1.

-- 
Terry Jan Reedy




More information about the Python-list mailing list