On 16/10/2017 18:53, Stefan Ram wrote:
Ian Kelly <ian.g.ke...@gmail.com> writes:
I honestly can't remember the last time I programmed an endless loop,
and I also can't remember the last time I used a while loop.
Those two things are probably related.

   My Python installation has a "Lib" directory.

   »^ +\bwhile\b.*:$« has 1348 hits in this directory,
   »^ +\bfor\b.*:$« has 8713. That's a ratio of 6.46.

   In other words, while-loops are only 13 % of all loops
   (while or for). That's a clear minority. But it does
   not indicate that while loops are used almost ever.

It's presumably a characteristic of the language. And it depends on what the language offers, so if there was no 'while' at all, I guess it would be 100% 'for'.

(I just looked through my non-Python language at a couple of projects and got these figures:

  forall       29%    (Equivalent to Python 'for')
  for          36%    (Simple iteration)
  while        14%    (about the same as your figure)
  repeat-until  3%
  N-times      11%
  endless loop  6%

11% N-times loops doesn't sound a lot but it's one in every 9 loops. What the figures don't show is that the N-times and endless loops are probably used more with short test programs than in final applications, so having a very quick way to express them is convenient.)


--
bartc

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

Reply via email to