do loop
Kristian Ovaska
kristian.ovaska at helsinki-nospam.fi.invalid
Fri Jan 16 12:20:03 EST 2004
beliavsky at aol.com:
>In a Python 'for' loop, one can change the value of looping variable,
[...]
>Is there a way to write a loop in Python that enforces this
>constraint? Should such functionality be added to the language?
In Python, "for i in range(3)" produces a sequence [0, 1, 2] and binds
each element to i in turn. It's the sequence that drives the loop; i
is more like a placeholder, and you are free to bind some other value
to it if you wish - it doesn't change loop semantics. So, it makes no
sense to restrict i.
--
Kristian Ovaska - http://www.cs.helsinki.fi/u/hkovaska/en/
More information about the Python-list
mailing list