<story><title>Python’s For - Else</title><url>http://book.pythontips.com/en/latest/for_-_else.html</url></story><parent_chain><item><author>askvictor</author><text>The word else implies something different to what it does (IMHO at least). In and if&amp;#x2F;else clause, the else happens when the primary&amp;#x2F;expected thing doesn&amp;#x27;t happen. I would expect that for a loop, an else clause would happen when the loop does _not_ finish normally, or if they loop is empty. I&amp;#x27;m sure it&amp;#x27;s a useful clause in certain cases, but the meaning of the word used is reversed. It might be  better use &amp;#x27;then&amp;#x27; or something like that:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  for i in l:
     print(i)
  then:
     print(&amp;quot;iteration finished without breaking&amp;quot;)&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>jimmytucson</author><text>Here’s why (Hettinger):&lt;p&gt;&amp;gt; In 1991, “else” was the obvious choice because of the traditional way compilers implemented while-loops: pastebin.com&amp;#x2F;tY35CTJ4&lt;p&gt;That is, “if I haven’t finished the loop, GOTO the body.”&lt;p&gt;He says if he had a time machine he could tell Guido in the future we’re all using structured programming so no one will find “else” intuitive; call it “nobreak” instead:  &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;m.youtube.com&amp;#x2F;watch?v=OSGv2VnC0go#&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;m.youtube.com&amp;#x2F;watch?v=OSGv2VnC0go#&lt;/a&gt;&lt;p&gt;Guido says if he had a time machine he would not have included the feature at all: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;mail.python.org&amp;#x2F;pipermail&amp;#x2F;python-ideas&amp;#x2F;2009-October&amp;#x2F;006157.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;mail.python.org&amp;#x2F;pipermail&amp;#x2F;python-ideas&amp;#x2F;2009-October&amp;#x2F;...&lt;/a&gt;&lt;p&gt;This whole thing was Knuth’s idea, not Guido’s: &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;citeseerx.ist.psu.edu&amp;#x2F;viewdoc&amp;#x2F;download?doi=10.1.1.103.6084&amp;amp;rep=rep1&amp;amp;type=pdf&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;citeseerx.ist.psu.edu&amp;#x2F;viewdoc&amp;#x2F;download?doi=10.1.1.103...&lt;/a&gt;</text></comment>
<story><title>Python’s For - Else</title><url>http://book.pythontips.com/en/latest/for_-_else.html</url></story><parent_chain><item><author>askvictor</author><text>The word else implies something different to what it does (IMHO at least). In and if&amp;#x2F;else clause, the else happens when the primary&amp;#x2F;expected thing doesn&amp;#x27;t happen. I would expect that for a loop, an else clause would happen when the loop does _not_ finish normally, or if they loop is empty. I&amp;#x27;m sure it&amp;#x27;s a useful clause in certain cases, but the meaning of the word used is reversed. It might be  better use &amp;#x27;then&amp;#x27; or something like that:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  for i in l:
     print(i)
  then:
     print(&amp;quot;iteration finished without breaking&amp;quot;)&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>rlayton2</author><text>I&amp;#x27;m a strong python advocate and rarely use for&amp;#x2F;else for this exact reason. It makes &lt;i&gt;more&lt;/i&gt; sense to me for it to be the other way (your way) around. I always add a comment on the else when I do too, to ensure that future readers don&amp;#x27;t make the same mistake.</text></comment>