Is using range() in for loops really Pythonic?

Dave Parker daveparker at flamingthunder.com
Mon May 19 22:51:41 EDT 2008


Your point about for-loops was applicable not only to Python, but to
many other programming languages.  So in response, I've added two new
for-loop variations to Flaming Thunder.

The two new variations are for-forever-do and for-expression-times-do.
For-forever allows you to explicitly create infinite loops, and for-
expression-times allows you to do something a specific number of times
without having to declare a looping variable if you don't need one.
Examples:

   Write "Fa".  For 8 times do write "-la".

   For forever do
     (
     Write "Do you know the definition of insanity? ".
     Read response.
     ).

On May 10, 8:19 pm, John Salerno <johnj... at NOSPAMgmail.com> wrote:
> I know it's popular and very handy, but I'm curious if there are purists
> out there who think that using something like:
>
> for x in range(10):
>     #do something 10 times
>
> isunPythonic. The reason I ask is because the structure of the for loop
> seems to be for iterating through a sequence. It seems somewhat
> artificial to use the for loop to do something a certain number of
> times, like above.
>
> Anyone out there refuse to use it this way, or is it just impossible to
> avoid?




More information about the Python-list mailing list