Why not allow empty code blocks?

Chris Angelico rosuav at gmail.com
Sat Jul 30 09:36:44 EDT 2016


On Sat, Jul 30, 2016 at 11:06 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> "for i in range(N):" just to repeat a block N times...
>
> Why should there be special syntax just for repeating a block N times?
> There's a general purpose for-loop which performs iteration. Why do you
> need special syntax to do what it already does?

Python could have chosen to make integers iterable, such that you say:

for i in 10:

but I don't think it really improves readability. It wouldn't
materially damage the language, though - the 'for' loop still does
exactly what it does, the rules are still just as simple. The only
question would be: why can't floats be iterable too? I mean, "for i in
3.5" should start half way down the loop body, complete that loop, and
then do three complete loops.

ChrisA



More information about the Python-list mailing list