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 {


} while( condition );

Aug 6, 2018 in Python by bug_seeker
• 15,550 points

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:


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

answered Aug 6, 2018 by Priyaj
• 58,140 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 5, 2020 in Python by Composer3
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 27, 2019 in Python by Olly
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
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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,362 views
0 votes
0 answers
+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,810 points
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,140 points
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