on the popularity of loops while and for

Peter J. Holzer hjp-python at hjp.at
Sat Sep 4 06:21:14 EDT 2021


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.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20210904/5ac2735c/attachment.sig>


More information about the Python-list mailing list