a gap of do....while?

S

StarWing

okay, I think somethings do....while is useful, but why python didn't
have it?

in lisp, we can (while (progn ....))
and in all other language we have do...while.
but in python, we only can:
cond = 1
while cond:
cond = 0
.....
if ....: cond = 1

has any polite way to handle this?
 
C

Chris Rebert

okay, I think somethings do....while is useful, but why python didn't
have it?

For simplicity of syntax and less duplication among the basic
syntactic constructs.
in lisp, we can (while (progn ....))
and in all other language we have do...while.
but in python, we only can:
cond = 1
while cond:
   cond = 0
   .....
   if ....: cond = 1

has any polite way to handle this?

It's essentially the same:

while True:
...
if not cond: break

This is considered idiomatic; and FWIW, I see do-while as having no
significant advantage over this.

Cheers,
Chris
 
C

Chris Rebert

It's essentially the same:

while True:
   ...
   if not cond: break

Substituting in the appropriate conditional expression for cond of
course (your use of cond for the flag caught me off guard).

Cheers,
Chris
 
S

StarWing

Substituting in the appropriate conditional expression for cond of
course (your use of cond for the flag caught me off guard).

Cheers,
Chris

Thank you, this is nice than mine :)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top