PEP-0315--Enhanced While Loop: An idea for an alternative syntax

T

Terry Carroll

Push the "yucky" while 1: loop into a generator function,
and then use a regular "for" loop in the multiple places
you need to handle a file in this way:

Sure; there's no question that you can usually move awkward code
constructs to a different location in the program.
 
P

Peter Maas

The do block is no safeguard against copy errors because it's optional.
A comment saves the same purpose. Replace

do:
init()
while cond():
body()

by

# init while
init()
while cond():
body()


PEP-0315 shouldn't be added to Python.

Mit freundlichen Gruessen,

Peter Maas
 
P

Paul Rubin

Peter Maas said:
The do block is no safeguard against copy errors because it's optional.
A comment saves the same purpose. Replace

do:
init()
while cond():
body()

by

# init while
init()
while cond():
body()

No, you don't understand. The initialization is part of the loop.
That is, the replacement for the do loop is

while 1:
init()
if not cond: break
body()
PEP-0315 shouldn't be added to Python.

I agree, but the reasoning has to go a bit further.
 
S

Stefan Axelsson

Just for the record, that was actually written by François Pinard, not
me. Well worth quoting again, though, as it's a lovely example.

Ah, my bad. I thought I cut the right attribution. At least I didn't
claim that *I* had written it. :)

Stefan,
 
P

Peter Maas

Paul said:
No, you don't understand. The initialization is part of the loop.
That is, the replacement for the do loop is

while 1:
init()
if not cond: break
body()

You are right, sorry. I was a bit hasty, thanks for the correction.
I reread the PEP and now realize that it is about situations like

<setup code>
while <condition>:
<loop body>
<setup code>

So the setup code is there to guarantee at least one execution
of the loop body. If this is the case, then the proposed form
"do <setup code> while" is misleading in my opinion. I would
merge <setup code> and <loop body> to <theBody> and solve the
problem with code like

do:
<theBody>
breakif <cond>

This would be clearer but I would mind this as well because
I like the minimality of Python and I am completely satisfied
with

while 1:
<theBody>
if <cond>: break

Mit freundlichen Gruessen,

Peter Maas
 
P

Peter Maas

Peter said:
> do:
> <theBody>
> breakif <cond>
>

I forgot the situation

do:
<Body1>
breakif <cond>
<Body2>

I was totally misguided by the term "setup" for <Body1>. In my
understanding a setup happens once like in C's

for(<setup>;<cond>;<next>)
...

Mit freundlichen Gruessen,

Peter Maas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top