do...until wisdom needed...

Ixokai news at myNOSPAM.org
Mon Apr 16 01:18:23 EDT 2001


The standard Python Idiom (tm of someone, I'm sure :)) for a do-while
construct is:

while 1:
    statements
    if condition:
        break

Its in-elegant, and even ugly, IMHO. I think there's a reason that there is
no do-while construct, otherwise I can't fathom why they wouldn't have put
it in yet.. this is something that comes up frequently.

--Stephen
(replace 'NOSPAM' with 'myseraph' to respond in email)

"Ken Peek" <Peek at LVCM.comNOSPAM> wrote in message
news:tdku4kqlqjquf2 at corp.supernews.com...
> Sometimes, when writing code, I find it would be nice if there were a
> "do...until" construct in Python.  This would be preferable to using a
"while"
> construct if you wanted to make sure the loop will execute at least once.
You
> CAN do this with a "while" construct, but it requires fiddling with the
loop
> condition before the "while" construct, which is "messy".  An example:
>
> condition = TRUE   # make sure loop runs at least once
> while (condition):
>     # do some stuff
>     # do some more stuff
>     condition = whatever_stops_the _loop
>
> Here is my question--  If Python WERE to have a "do...until" construct,
what
> would be the best way to implement the syntactical rules?
>
> For example:
>
> do:
>     # some stuff
>     # some more stuff
>     until (condition == TRUE)   # ("until" must be last statement or there
is an
> error)
>
> OR:
>
> do:
>     # some stuff
>     # some more stuff
> until (condition == TRUE)
>
> OR: ???
>
>
>




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list