<br><br><div class="gmail_quote">2009/10/2 Yuvgoog Greenle <span dir="ltr"><<a href="mailto:ubershmekel@gmail.com">ubershmekel@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr"><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
Nonsense - there are several other ways to break out of a loop. Raising an exception or returning for example</blockquote><div><font face="arial, sans-serif"><span style="border-collapse: collapse;"><br>
</span></font></div></div><div><font face="arial, sans-serif"><span style="border-collapse: collapse;">I do appreciate your response. I'd like you to examine how the "else" in question isn't relevant to the discussion of return or raise:</span></font></div>

<div><font face="arial, sans-serif"><span style="border-collapse: collapse;"><br></span></font></div><div><div>>>> for i in range(10):</div><div>...     print(1/0)</div>
<div>... else:</div><div>...     print(100)</div><div>...</div><div>Traceback (most recent call last):</div><div>  File "<stdin>", line 2, in <module></div><div>ZeroDivisionError: int division or modulo by zero</div>

</div><div>>>></div></div></blockquote><div><br><br>The point is that the exception may be handled at an outer level - so the loop is broken out of and control flow is handed to another part of the code. Code that *always* raises an exception to break the loop is not common or interesting, but code that does so under certain circumstances is not uncommon (raising an exception is one way to break out of nested loops - the other way is an early return...)<br>
<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><div><div><div>>>> def eggs():</div><div>...     for i in range(10):</div>
<div>...             return 1234</div><div>...     else:</div><div>...             print(69)</div><div>...</div>
<div>>>> eggs()</div><div>1234</div></div></div><div>>>> </div><br></div>
</blockquote></div><br>The return may be conditional in order to explicitly break out of the loop under certain circumstances.<br><br><br clear="all">Michael<br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br>
<br><br>