On Thu, Feb 4, 2010 at 4:59 AM, Jean-Michel Pichavant <span dir="ltr"><<a href="mailto:jeanmichel@sequans.com">jeanmichel@sequans.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">What the hell is this 'for else' loop !! :D First time I see this statement for years.</div>
I'd never thought I'd still learn something that basic.<br></blockquote><div><br></div><div>Its one of the least used constructs in Python, I think, and leads to periodic statements like this on the list where people who think they know all about Python suddenly see it and go WTF :)</div>
<div><br></div><div>But in Python, all loops have an "else" clause that is fired when the loop terminates-- but *only* if it terminates normally, where 'normally' is basically, 'if you don't use break to exit the loop prematurely'.</div>
<div><br></div><div>It allows you to do certain things in a way which is (arguably, and I so don't want to start an argument about this) a bit cleaner, where the normal method would require a flag or some such. For example, if you need want to loop over a sequence to test to see if they all match some criteria, you can use a for..else, or some flag variable.</div>
<div><br></div><div><br></div></div><div name="mailplane_signature">--S</div>