You don't have to: use the break statement, that's what it's for.
About people teaching students not to use it: the existence of bad
teachers teaching silly ideas is not a reason to add syntax to
Python.
--Ned.
You shouldn't have
to invoke takewhile and a lambda just to break out of for
loop.
>http://docs.python.org/2/library/itertools.html#itertools.takewhile
>
>for item in takewhile(lambda x: x < 5, range(10)):
> pass
>>
>> [People who avoid the 'break' by functionalizing an inner portion of the
>> loop are just kidding themselves and making their own code worse, IMO.
>> Takewhile from itertools also works, but that's clumsy and wordy as well.]
>>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas