[Tutor] Language truce
D-Man
dsh8290@rit.edu
Mon, 2 Jul 2001 14:56:37 -0400
On Thu, Jun 28, 2001 at 02:20:58PM -0700, Danny Yoo wrote:
| One reason that 'for/in' might be preferred is because we are guaranteed
| that the loop will always terminate: there can only be a finite number of
| elements in a list. That's one big advantage of a loop construct that
| goes along elements --- theoretically, we'll never get into infinite
| loops.
Almost.
l = range( 1 )
for i in l :
print l
l.append( i+1 )
Don't do this! It's just as bad in C or any other language --
mutating a collection while iterating over it is just a bad idea.
-D