for-else
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Wed Mar 5 19:39:08 EST 2008
On Mar 5, 10:44 pm, "Troels Thomsen" <nej tak ...> wrote:
> > The primary use case is searching a container:
>
> > prep_tasks()
> > for item in container:
> > if predicate(item):
> > found_tasks()
> > break
> > else:
> > not_found_tasks()
> > follow_up_tasks
>
> I've found myself mimicing this again and again in c, and was pleased to
> find it in python and use it regularely.
> int i
> for (i = 0 ; i < 10 ; ++i)
> blah
> if i == 10
> not_found_tasks()
>
> The discussion of words is silly. My surprise about "else following a for
> loop.... what the heck ...." lasted excactly as long as it takes to read
> this sentence.
>
> tpt
More information about the Python-list
mailing list