PEP-315 ("do" loop)
and-google at doxdesk.com
Tue Feb 17 20:05:41 CET 2004
John Roth <newsgroups at jhrothjr.com> wrote:
> 1. The proposed syntax breaks Python's indentation scheme in a manner that
> try-except, for-else, while-else, and if-elif-else do not.
I don't know about 'breaks', but IMO the main disadvantage of the 315
proposal is that you have to read code backwards. That is, given:
you have to scan backwards to see whether the while block is stand-alone or
part of a do...while construct.
This could be solved by starting with a 'while' construct as normal and then
following it with the new keyword:
('anwhile' is by analogy with 'elif', but anything could be used.)
This also has the advantage that more than one anwhile clause could be used,
giving a general-purpose multi-test loop.
Wayne's 'until' proposal is simpler than 315 and only allows a post-test,
not a mid-test loop.
IMO the word 'until' is not a good choice as it inverts the condition logic:
now the condition must be False to continue the loop instead of True as with
'while' and 'if'. If the difference is just that the loop executes at least
once without checking the condition, we could do it with a variant of while
syntax, for example:
while condition, 1:
(PXTL has something like this: px:while elements may have a 'min' attribute
giving a minimum number of untested iterations. Seems to work OK, though I
have never had cause to use a number other than 1.)
> 2. What I find more serious is that there are a huge number of ways to go in
> "improving" the basic while loop, none of which seem to be a natural
> stopping point.
Indeed. I would quite like to use 'anwhile', but only *quite* - It's a *bit*
nicer than "if not condition: break", but not enormously so.
At best, I'm +0 on loop enhancements in general.
mailto:and at doxdesk.com
More information about the Python-list