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.

See PEP 315 -- Enhanced While Loop:

Rejected [...] because no syntax emerged that could compete with the following form:

    while True:
        <setup code>
        if not <condition>:
            break
        <loop body>

A syntax alternative to the one proposed in the PEP was found for a basic do-while loop but it gained little support because the condition was at the top:

    do ... while <cond>:
        <loop body>

or, as Guido van Rossum put it:

Please reject the PEP. More variations along these lines won't make the language more elegant or easier to learn. They'd just save a few hasty folks some typing while making others who have to read/maintain their code wonder what it means.

Answer from Martijn Pieters on Stack Overflow
Top answer
1 of 2
86

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.

See PEP 315 -- Enhanced While Loop:

Rejected [...] because no syntax emerged that could compete with the following form:

    while True:
        <setup code>
        if not <condition>:
            break
        <loop body>

A syntax alternative to the one proposed in the PEP was found for a basic do-while loop but it gained little support because the condition was at the top:

    do ... while <cond>:
        <loop body>

or, as Guido van Rossum put it:

Please reject the PEP. More variations along these lines won't make the language more elegant or easier to learn. They'd just save a few hasty folks some typing while making others who have to read/maintain their code wonder what it means.

2 of 2
9

Because everyone is looking at it wrong. You don't want DO ... WHILE you want DO ... UNTIL.

If the intitial condition is true, a WHILE loop is probably what you want. The alternative is not a REPEAT ... WHILE loop, it's a REPEAT ... UNTIL loop. The initial condition starts out false, and then the loop repeats until it's true.

The obvious syntax would be

repeat until (false condition):
  code
  code

But for some reason this flies over everyone's heads.

🌐
Reddit
reddit.com › r/python › why not add do-while loops to python?
r/Python on Reddit: Why not add do-while loops to Python?
August 30, 2019 -

It continues to puzzle me why we have no do-while loop in Python.

In Python code, it's common to see the following pattern:

# ... some code ....
while condition:
    # ... same code copied here ...

This is of course prone to problems because of the "minor" code duplication.

Alternatively, you might see this better option:

def some_code():
    # ... some code ...

some_code()
while condition:
    some_code()

This involves creating a function even though IMHO it often serves to bloat the code unnecessarily.

And than there's this variation:

while True:
    # ... do something ...
    if not condition:
        break

IMHO, this approach, especially when the body of the loop is fairly large, fails to communicate the logical intent of the code in a clean manner.

Of course - all of these approaches do work. But IMHO a syntax which could clarify programmer's intent in the most precise and concise way is the following classical do-while:

do:
    # ... do something ...
    while some_condition

I know that years ago do-while style constructs have been proposed in PEPs and rejected.

But isn't it time we review the idea again? I think there is a considerable amount of code which could benefit from this.

Would love to hear your thoughts :)

Discussions

As a beginner how do I understand while loops?
It’s just a loop which continues running until the condition becomes false. More on reddit.com
🌐 r/learnpython
76
36
April 10, 2025
Why not add do-while loops to Python?
I think the assignment expressions of PEP 572 are being implemented partly because of this. It’s even one of the examples: https://www.python.org/dev/peps/pep-0572/#id22 More on reddit.com
🌐 r/Python
22
3
August 30, 2019
🌐
Quora
quora.com › Why-is-there-no-do-while-loop-in-Python
Why is there no 'do while' loop in Python? - Quora
Answer (1 of 6): Didn't do much research on it but a quick Google turned up with this answer and the answer seems legit considering it refference to PEP Python : Why there is no do while loop in python Here is it. Also in case you are trying to relate python and C dont. One is a language which ...
🌐
freeCodeCamp
freecodecamp.org › news › python-do-while-loop-example
Python Do While – Loop Example
August 31, 2021 - If the number the user submits is negative, the loop will keep on running. If it is positive, it will stop. Python does not have built-in functionality to explicitly create a do while loop like other languages.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-do-while
Python Do While Loops - GeeksforGeeks
July 23, 2025 - In Python, there is no construct defined for do while loop.
🌐
Edureka Community
edureka.co › home › community › categories › python › why there is no do while loop in python
Why there is no do while loop in python | Edureka Community
August 6, 2018 - Why doesn't Python have a 'do while' loop like many other programming language, such as C? Example : ... do { statement(s); } while( condition );
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 39804 › do-while-loop-in-python
do-while loop in python [SOLVED] | DaniWeb
Python does not have a built-in do...while, but you can emulate "run at least once, then decide" cleanly. Use a boolean updated at the end of each iteration (avoid strings like "true"/"false", and prefer logical and over bitwise &): finished ...
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › do-while-loop-python
Emulating a Do-While Loop in Python: A Comprehensive Guide for Beginners | DataCamp
January 31, 2024 - This helps prevent infinite loops and allows for more control over loop execution. In some programming languages, a "do-while" loop ensures that the code within the loop executes at least once before checking the condition. Python does not have a built-in "do-while" loop, but you can emulate ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › do while loop in python
Do While Loop in Python | Emulate Do While Loop in Python(Example)
March 17, 2023 - In the python body of the while, the loop is determined through indentation. As there is no proper indentation for specifying do while loop in python, therefore there is no do-while loop in python, but it is done with while loop itself.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Real Python
realpython.com › python-do-while
How Can You Emulate Do-While Loops in Python? – Real Python
August 2, 2022 - In a while loop, there’s no guarantee of running the loop’s body. If the loop condition is false from the start, then the body won’t run at all. Note: In this tutorial, you’ll refer to the condition that controls a while or do-while loop as the loop condition. This concept shouldn’t be confused with the loop’s body, which is the code block that’s sandwiched between curly brackets in languages like C or indented in Python...
🌐
Texas Instruments
education.ti.com › en › resources › computer-science-foundations › do-while-loops
Python coding: Do While Loops | Texas Instruments
Note that this loop structure is slightly different than Do While loop structures that appear in other programming languages. Python doesn’t have a built-in Do While loop structure, but the behavior of a Do While loop can be modeled with programs that use While, If and break commands as we’re exploring here.
🌐
TutorialsPoint
tutorialspoint.com › home › articles on trending technologies › why there is not do...while loop in python?
Why there is not do...while loop in Python?
July 30, 2019 - PEP 315 (Python Enhancement Proposal) to include do..while statement has been rejected because it doen't fit in the general format of indented block statement: indented block used by every other Python compound statement.
🌐
Javatpoint
javatpoint.com › python-do-while-loop
Python Do While Loop - Javatpoint
Python Do While Loop - The do while loop is used to check condition after executing the statement. It is like while loop but it is executed at least once.
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
There is no do while loop in Python, but you can modify a while loop to achieve the same functionality.
🌐
Scaler
scaler.com › home › topics › python do while loop
Python Do While Loop - Scaler Topics
December 1, 2023 - Since there is not an in-built do while loop in python, we implemented the do-while Loop in Python using for-loop and while-loop, which are already present in the language.
🌐
Sololearn
sololearn.com › en › Discuss › 2754843 › does-python-have-dowhile-loop
Does python have do-while loop? | Sololearn: Learn to code for FREE!
April 14, 2021 - Python doesn't have a built-in `do-while` loop like some other programming languages, such as C or Java. However, you can achieve similar functionality using a `while` loop in combination with a conditional check at the end.
🌐
Quora
quora.com › Is-Python-really-such-a-flawed-language-that-it-doesnt-even-have-a-do-while-loop
Is Python really such a flawed language that it doesn't even have a 'do {} while ()' loop? - Quora
Answer (1 of 7): The number of times that I’ve had to use a do - while loop rather than a while loop I can count on one hand. So do while is really not a necessary feature of a language to have. Given this there really is no need for a language to have do while, especially in light of constructi...
🌐
Educative
educative.io › answers › how-to-emulate-a-do-while-loop-in-python
How to emulate a do-while loop in Python
Even though Python doesn’t explicitly have the do-while loop, we can emulate it. There are two scenarios in which a loop terminates: The loop condition is no longer true/false (depending on the type of loop).