On 03/10/06, Alan Gilfoy <[EMAIL PROTECTED]> wrote: > > >>>> for i in range(10): > > ... break > > ... else: > > ... print 'foo' > > ... > >>>> for i in range(10): > > ... pass > > ... else: > > ... print 'foo' > > ... > > foo > >>>> > > pardon the newb question, but what do these code lines do?
They demonstrate when the else: clause in a for statement gets executed. Spaces sometimes get lost in email, so I'll write them again, with underscores instead of spaces: for i in range(10): ____break else: ____print 'foo' In this case, the for loop will exit because of the break statement, and so the else: clause will not execute. for i in range(10): ____pass else: ____print 'foo' In this case, the loop body is just 'pass', which is python's do-nothing statement. So the loop will exit normally, and the else: clause will execute (resulting in the string 'foo' being printed). Does this help? -- John. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor