Hans Polak wrote: > Hi Nick, > > Yep, PEP 315. Sorry about that. > > Now, about your suggestion > do: > <setup code> > while <condition> > <loop body> > else: > <loop completion code> > > This is pythonic, but not logical. The 'do' will execute at least once, so > the else clause is not needed, nor is the <loop completion code>. The <loop > body> should go before the while terminator.
This objection is based on a misunderstanding of what the else clause is for in a Python loop. The else clause is only executed if the loop terminated naturally (the exit condition became false) rather than being explicitly terminated using a break statement. This behaviour is most commonly useful when using a for loop to search through an iterable (breaking when the object is found, and using the else clause to handle the 'not found' case), but it is also defined for while loops. Regards, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com