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,300 points
77 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,140 points

Related Questions In Python

0 votes
1 answer

Do-while loop in Python

Python does not have a do-while construct.  If ...READ MORE

answered May 11, 2018 in Python by Hamartia's Mask
• 1,580 points
74 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 27 in Python by Olly
23 views
+1 vote
3 answers
0 votes
1 answer

Is there a foreach function in python and is there a way to implement it if there isnt any

Every occurence of "foreach" I've seen (PHP, ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,710 points
55 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
69 views
+4 votes
6 answers
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
• 56,140 points
98 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 in Python by anonymous
23 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.