Fuzzyman wrote: > Nick Coghlan wrote: >> In my example, the 3 sections (<setup code>, <loop body> and <loop >> completion >> code> are all optional. A basic do-while loop would look like this: >> >> do: >> <setup code> >> while <condition> >> >> (That is, <setup code> is still repeated each time around the loop - it's >> called that because it is run before the loop evaluated condition is >> evaluated) >> >> > > +1 > > This looks good.
I'm pretty sure it was proposed by someone else a long time ago - I was surprised to find it wasn't mentioned in PEP 315. That said, Guido's observation on PEP 315 from earlier this year holds for me too: "I kind of like it but it doesn't strike me as super important" [1] > The current idiom works fine, but looks unnatural : > > while True: > if <condition>: > break There's the rationale for the PEP in a whole 5 lines counting whitespace ;) > Would a 'while' outside of a 'do' block (but without the colon) then be > a syntax error ? > > 'do:' would just be syntactic sugar for 'while True:' I guess. That's the slight issue I still have with the idea - you could end up with multiple ways of spelling some of the basic loop forms, such as these 3 flavours of infinite loop: do: pass # Is there an implicit 'while True' at the end of the loop body? do: while True while True: pass The other issue I have is that I'm not yet 100% certain it's implementable with Python's parser and grammar. I *think* changing the definition of the while statement from: while_stmt ::= "while" expression ":" suite ["else" ":" suite] to while_stmt ::= "while" expression [":" suite ["else" ":" suite]] And adding a new AST node and a new type of compiler frame block "DO_LOOP" would do the trick (the compilation of a while statement without a trailing colon would then check that it was in a DO_LOOP block and raise an error if not). Cheers, Nick. [1] http://mail.python.org/pipermail/python-dev/2006-February/060711.html -- 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