Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't there a do while flow control statement in python?

Tags:

python

Is there a good reason why there isn't a do while flow control statement in python?

Why do people have to write while and break explicitly?

like image 839
the_drow Avatar asked Feb 03 '10 13:02

the_drow


People also ask

Do While exists in Python flow control?

Introduction to Do While Loop in Python. The Do While Loop conditional statement is used for an exit level control flow of code implementation that ensures the code block is executed at least once before the control reaches the while condition.

Why there is no do while loop in Python?

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. and have the exact same effect as a C do { .. }

Why do you think Python programming language does not include a Do While loop control structure like C++ or Java?

Python doesn't have a do-while loop construct. Why? Apparently, the core developers never found a good syntax for this type of loop. Probably, that's the reason why Guido van Rossum rejected PEP 315, which was an attempt to add do-while loops to the language.

Is while a control statement in Python?

while loop: In Python, while loops are used to execute a block of statements repeatedly until a given condition is satisfied. Then, the expression is checked again and, if it is still true, the body is executed again. This continues until the expression becomes false.


2 Answers

It has been proposed in PEP 315 but hasn't been implemented because nobody has come up with a syntax that's clearer than the while True with an inner if-break.

like image 193
Pär Wieslander Avatar answered Sep 21 '22 09:09

Pär Wieslander


Probably because Guido didn't think it was necessary. There are a bunch of different flow-control statements you could support, but most of them are variants of each other. Frankly, I've found the do-while statement to be one of the less useful ones.

like image 37
JesperE Avatar answered Sep 17 '22 09:09

JesperE