# [Python-ideas] Simpler syntax for basic iterations

Luciano Ramalho luciano at ramalho.org
Mon Oct 12 00:13:27 CEST 2015

```On Sun, Oct 11, 2015 at 7:03 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Luciano Ramalho <luciano at ramalho.org>
> writes:
>> for n:  # repeat block n times
>>      fd(100)
>>      lt(360/n)
>>
>> Where n is any expression that evaluates to an integer.
>
> Huh? If ‘n’ is an expression that evaluates to one integer, then why are
> you also dividing by that one integer ‘n’ every time through?

That's the classic formula for drawing an N-sided polygon in Logo. N
can be any positive integer. Maybe this is clearer:

for 3:  # draw a triangle
fd(100)
lt(120)

> I don't claim it will convince you, but I find compelling the fact that
> this::
>
>     for n in range(FOO):
>          fd(100)
>          lt(360/n)
>
> already works fine and is quite clear.

It is quite clear for us. When teaching the first steps of programming
to kids with the Turtle module, `for x in range(n):` leaves us in the
unfortunate position of having to say: "we won't use that x for
anything, and I can't explain what range this until much later..."

Cheers,

Luciano

>
> --
>  \         “Science is a way of trying not to fool yourself. The first |
>   `\     principle is that you must not fool yourself, and you are the |
> _o__)               easiest person to fool.” —Richard P. Feynman, 1964 |
> Ben Finney
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

--
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Professor em: http://python.pro.br