for ... else ?

Matthieu TC matthieutc at yahoo.com
Wed Jun 13 07:11:10 CEST 2007


> > > On 6/12/07, Gabriel Genellina <gagsl-... at yahoo.com.ar> wrote:

> > >> for x in iterable:

> > >>    do something with x

> > >> else:

> > >>    do something when there are no more x

> >

> > >> You can think the above as:

> >

> > >> while there are still values in iterable:

> > >>    do something with the next value

> > >> else:

> > >>    do something when there are no more items




Also, if the for loop ends because of a break statement, the else part will never be executed..

-mats














More information about the Python-list mailing list