Subject: "do" as a keyword
From: Neil Cerutti
Date: 12/11/2007 3:06:31 PM
On 2007-12-11, cokofreedom@gmail.com <cokofreedom@gmail.com> wrote:
> First off let me state that I really enjoy using Python. I am a
> 3rd year student and have been using python for 3 months,
> (thanks to trac!). I do not consider myself an experienced or
> clever programmer, but I am able to get by.
>
> Something I love about Python is that almost everything you do
> can be written in pseudo code then carried across into Python
> without a great- deal of difference.
>
> But reading through the warts and reading about a lack of "do
> while statements" I also started to ponder about the "'do
> something' if 'true' else 'do this'", and pondered if perhaps
> this statement could do with the including of the keyword do.
>
> It would clear up the usage of such a statement because it
> would read happily. Or am I making a mountain out of an ant
> hill?
When I use languages that supply do-while or do-until looping
constructs I rarely need them.
I personally miss
for init; condition; next:
more than do-while, but the structured for loop doesn't fit in
Python since init and next would (probably) have to be statements
(or statement suites) rather than expressions. Hence, the cool
innovations of iterators and generators, which otherwise might
not have found a home in Python. I wonder what programming Python
was like before iterators sometimes.
However, did you have an specific need for a do-while construct?
Perhaps we could show you the alternatives.
--
Neil Cerutti
Subject: "do" as a keyword
From: Terry Reedy
Date: 12/11/2007 11:11:54 PM
"Steven D'Aprano" <steve@REMOVE-THIS-cybersource.com.au> wrote in message
news:13lts6gb9t2j350@corp.supernews.com...
||
| But loops that run at least once is a basic element of algorithms.
| Perhaps not as common as the zero or more times of the while loop, but
| still fundamental. It is a shame it has to be faked using:
|
| while True: # force the first iteration to always run
| process
| if condition: break
|
| Ugly and misleading.
I disagree. Nothing is being faked. The generic loop is
while True:
pre_process
if condition: break
post_process
If there is no pre_process, abbreviate the first two lines as 'while
condition:'. If there is no post_process, some would like another
abbreviation. Understanable. But the use cases seem relatively few. And
anyway, a competant programmer must understand the generic loop and a
fraction form, which I believe is at least as common as the no post_process
case.
Terry Jan Reedy
Subject: "do" as a keyword
From: Antoon Pardon
Date: 12/12/2007 1:07:33 PM
On 2007-12-12, Terry Reedy <tjreedy@udel.edu> wrote:
>
> "Steven D'Aprano" <steve@REMOVE-THIS-cybersource.com.au> wrote in message
> news:13lts6gb9t2j350@corp.supernews.com...
>||
>| But loops that run at least once is a basic element of algorithms.
>| Perhaps not as common as the zero or more times of the while loop, but
>| still fundamental. It is a shame it has to be faked using:
>|
>| while True: # force the first iteration to always run
>| process
>| if condition: break
>|
>| Ugly and misleading.
>
> I disagree. Nothing is being faked. The generic loop is
>
> while True:
> pre_process
> if condition: break
> post_process
>
> If there is no pre_process, abbreviate the first two lines as 'while
> condition:'. If there is no post_process, some would like another
> abbreviation. Understanable. But the use cases seem relatively few. And
> anyway, a competant programmer must understand the generic loop and a
> fraction form, which I believe is at least as common as the no post_process
> case.
And this generic loop is faked. There is no notion in the language that
somehow connects this if statement to be a breaking condition for a
loop. If it would be a real syntatic construct in the language, it would
probably look more like:
do:
pre_process
until condition:
post_process
Personnaly I would have preferred to have this one generic loop
construct with no abbreviations instead of having the while abbreviation
that is to be combined with a break statement to fake the generic loop.
--
Antoon Pardon
|