on the popularity of loops while and for

Hope Rouselle hrouselle at jevedi.com
Sat Sep 4 08:31:17 EDT 2021


"Peter J. Holzer" <hjp-python at hjp.at> writes:

> On 2021-08-29 10:04:47 +0100, Barry wrote:
>> > I'd like get a statistic of how often each loop is used in practice.  
>> > 
>> > I was trying to take a look at the Python's standard libraries --- those
>> > included in a standard installation of Python 3.9.6, say --- to see
>> > which loops are more often used among while and for loops.  Of course,
>> > since English use the preposition ``for'' a lot, that makes my life
>> > harder.  Removing comments is easy, but removing strings is harder.  So
>> > I don't know yet what I'll do.
>> > 
>> > Have you guys ever measured something like that in a casual or serious
>> > way?  I'd love to know.  Thank you!
>> 
>> I am interesting in why you think that choice of while vs. for is
>> about popularity?
>> 
>> Surely the choice is made in most cases by the algorithm?
>
> The context here is an introductory course for Python. So there is not
> "the algorithm", there are all the algorithms that a novice is likely
> to encounter.
>
> For me it makes absolute sense to base the contents of the course on
> popularity. Constructs which a novice programmer is very likely to use
> or encounter in other people's code should be covered more thoroughly
> than constructs that will be used only rarely. Some are so rare that
> they can be safely omitted. The while loop is certainly not in that
> category, but it probably makes sense to spend less time on it than on
> the for loop.

``A man after my own heart.''


More information about the Python-list mailing list