<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">[x for x in l if x < 10 else break]?<div><br></div><div><br></div><div><br></div><div><br><div><div>On Jun 25, 2013, at 10:08 AM, Ned Batchelder <<a href="mailto:ned@nedbatchelder.com">ned@nedbatchelder.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div text="#000000" bgcolor="#FFFFFF" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">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.<br><br>--Ned.<br><br><div class="moz-cite-prefix">On 6/25/2013 10:46 AM,<span class="Apple-converted-space"> </span><a class="moz-txt-link-abbreviated" href="mailto:jimjhb@aol.com">jimjhb@aol.com</a><span class="Apple-converted-space"> </span>wrote:<br></div><blockquote cite="mid:8D03FC9DB9F3EC0-1864-1C17F@webmail-m103.sysops.aol.com" type="cite"><font size="2" face="arial"><br><div style="font-family: arial, helvetica; font-size: 10pt;"><div id="AOLMsgPart_1_6fefd5c5-1a1a-4de7-83d4-1d0967ebd3b6"><font size="2" face="arial">You shouldn't have to invoke takewhile and a lambda just to break out of for loop.<br><div style="font-size: 10pt;"><div id="AOLMsgPart_0_bb27e8f8-4c9b-49b6-b5a4-d92139d83998" style="margin: 0px; font-size: 12px; background-color: rgb(255, 255, 255);"><pre style="font-size: 9pt;"><tt><a moz-do-not-send="true" style="font-family: Tahoma, Verdana, Arial, sans-serif;">>http://docs.python.org/2/library/itertools.html#itertools.takewhile</a><font face="Tahoma, Verdana, Arial, sans-serif">
>
>for item in takewhile(lambda x: x < 5, range(10)):
> pass
</font><font face="Arial, Helvetica, sans-serif">></font><font face="Tahoma, Verdana, Arial, sans-serif">>
>> [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.]
>>
</font></tt></pre></div></div></font></div></div></font><br><fieldset class="mimeAttachmentHeader"></fieldset><br><pre wrap="">_______________________________________________
Python-ideas mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org">Python-ideas@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/python-ideas">http://mail.python.org/mailman/listinfo/python-ideas</a>
</pre></blockquote><br>_______________________________________________<br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/python-ideas">http://mail.python.org/mailman/listinfo/python-ideas</a><br></div></blockquote></div><br></div></body></html>