no side effects

Bo M. Maryniuck b.maryniuk at forbis.lt
Wed Jan 8 12:22:39 EST 2003


On Wednesday 08 January 2003 15:10, Michele Simionato wrote:
> I was surprised by the following code:
> >>> for i in [1,2,3]:
> ...     print i,
> ...     i=3
> I would have expected only 1 to be printed, 
Wrong.

> but instead Python continues the loop 
Yes.

> Maybe others will appreciate that.
Probably you want this:
>>> for i in [1, 2, 3]:
...     print i
...     if i == 1:break
... 
1

-- 
Regards, Bogdan

Professionalism has no place in art, and hacking is art.  Software Engineering
might be science; but that's not what I do.  I'm a hacker, not an engineer.
		-- jwz






More information about the Python-list mailing list