on the popularity of loops while and for

Barry barry at barrys-emacs.org
Sun Aug 29 05:04:47 EDT 2021




> On 28 Aug 2021, at 22:42, Hope Rouselle <hrouselle at jevedi.com> 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?
If you have an iterator then you use for.
Of course you can use while instead of for but in code review that will get queried.

Barry



> -- 
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list