Why there is no do while loop in python

0 votes

Why doesn't Python have a 'do while' loop like many other programming language, such as C?

Example : In the C we have do while loop as below :

do {

statement(s);

} while( condition );

Aug 6, 2018 in Python by bug_seeker
• 15,520 points
7,559 views

1 answer to this question.

0 votes

There is no do...while loop because there is no nice way to define one that fits in the statement: indented block pattern used by every other Python compound statement. As such proposals to add such syntax have never reached agreement.

Nor is there really any need to have such a construct, not when you can just do:

while True:

   # statement(s)

if not condition:

   break

and have the exact same effect as a C do { .. } while condition loop.

answered Aug 6, 2018 by Priyaj
• 58,100 points

Related Questions In Python

0 votes
2 answers

Do-while loop in Python

A more pythonic way would be this: ``` while ...READ MORE

answered Jul 6, 2020 in Python by Composer3
1,355 views
0 votes
1 answer

Is there a way to loop between 0 and 1 by 0.1 in python?

You can use the linespace function. It ...READ MORE

answered May 28, 2019 in Python by Olly
3,036 views
0 votes
1 answer
0 votes
0 answers

What is the syntax for an empty while loop in python?

What kind of ambiguities are expected for ...READ MORE

Aug 5, 2019 in Python by Waseem
• 4,540 points
735 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,362 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,933 views
0 votes
1 answer

Is there a label/goto in Python?

No, Python does not support labels and ...READ MORE

answered Aug 1, 2018 in Python by Priyaj
• 58,100 points
828 views
0 votes
2 answers

Why do we use return statement in python?

def maximum(x, y):     if x > y:     ...READ MORE

answered Apr 4, 2019 in Python by anonymous
1,948 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP