Loop-and-a-half (Re: Curious assignment behaviour)

John Roth johnroth at ameritech.net
Sat Oct 13 00:03:18 EDT 2001


"Jyrinx" <jyrinx at mindspring dot com> wrote in message
news:9q84ob$1ls$1 at nntp9.atl.mindspring.net...

>
> Well, this is precisely what happens in C, right (for variables declared
in
> the loop)? Personally, I like that kind of strict scoping - it indicates
> that a variable introduced inside a loop is there on a temporary basis,
and
> has no purpose being used outside of it. If the programmer must initialize
> the variable before the loop because he intends to use it after the loop,
it
> makes it clearer to a reader, anyway, since the reader knows immediately
> that the loop iterator is somehow an important part of the result of the
> loop.

Yup. That's exactly why the original example that started this branch is
poor programming practice, in general. In the way it was used, it looks like
a debugging statement, and there is no good way in Python to say "run this
code after the loop, but only if the loop executed at least once."

John Roth

> Jyrinx
> jyrinx at mindspring dot com
>
>





More information about the Python-list mailing list