There is no do-while loop in Python.

This is a similar construct, taken from the link above.

 while True:
     do_something()
     if condition():
        break
Answer from theycallmemorty on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true.
Discussions

How to make a loop repeat until a condition is met. I want going left to be the condition that needs to be met.
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
12
0
November 22, 2022
How do you loop until correct input is given?
First find what loop you need. If the number of iterations is known beforehand then for. If not known then while. Then find how to draw a random number. Test in the python interpreter. Then find how to use the input function. Test in tje python interpreter. Brick by brick you will build you way ;) More on reddit.com
🌐 r/learnpython
33
29
February 25, 2022
I need help in understanding while loop
It's nothing more than a loop that keeps running as long as the condition you give it evaluates to True. If you do while True, you get an infinite loop. If you do white x > 3, you get a loop that keeps repeating as long as the value of x is greater than 3. If you do while someFunction(), you get a loop that keeps repeating as long as someFunction() returns True. If you do while False, it never runs anything at all. This code; x = 3 while x != 0: print(x) x -= 1 print("Done!") Basically performs these steps; Set x to 3 x is not 0, so run the loop once Print x, then decrement it by 1. x is now 2 x is still not 0, so run the loop again Print x, then decrement it by 1. x is now 1 x is still not 0, so the loop runs a 3rd time Print x, then decrement it by 1. x is now 0. x is now 0, so the while loop's condition now evaluates to False and the loop will not run again. Print "Done!" More on reddit.com
🌐 r/learnpython
12
1
August 18, 2023
How do while not loops work
In general, recall the while loop syntax. while : Conceptually, coding aside, consider filling a glass of water. Is there space for more water in the glass? Okay, then pour some. Without going in detail of how this funky glass object is defined, hopefully the following makes sense as a python analog of that process. while glass.has_space(): #we're still filling the glass glass.add_water() #glass is now full of water Without writing out how this glass object works, let's say it has another method for returning a boolean (True/False) for whether or not it is currently full, instead of the previous example of whether or not it had space for more water. We can fill the glass in the same way, but we have to negate that statement using the not operator while not glass.is_full(): #we're still filling the glass glass.add_water() #glass is now full of water Going back to the initial syntax, which is still the same, the only thing we've done is changing the condition statement of the loop. Instead of checking that glass.has_space() evaluates to True, we are now checking that the expression not glass.is_full() evaluates to True. That is the same statement as evaluating that glass.is_full() evaluates to False, because the only thing the not operator does to a boolean is negating it, i.e. True becomes False and vice versa. Now looking at your code linked, the condition for looping is that not sequenceCorrect evaluates to True, which is equivalent to the statement that sequenceCorrect is False. I won't paste the code here, but we see on line 3 that sequenceCorrect starts its life being False, so upon entering the while loop we do indeed step into that block of code because at that time not sequenceCorrect is in fact True. Then the first thing we do on line 5 is reassign it to True. If the remaining lines don't change it back to False, this will stop the while loop from repeating, since in this current state not sequenceCorrect evaluates to False. So you can say that line 5 is defaulting the loop to not going to be repeated. The only way for the loop to be repeated is for lines 6-8 with the nested for loop and if statement to find some character in dna that is not in "actgn", upon which sequenceCorrect will be assigned to False and thus the statement in the while loop not sequenceCorrect would evaluate to True and thus the loop would repeat itself once more. Personally, I think this is just a pretty unclear way to achieve the goal of checking the validity of that input string. I would have defined it another way, but I can't see anything wrong with it really. If the not operation in the while loop statement is bothering you, you could equally have rewritten the code with a variable for instance named sequenceIncorrect and just flipped all assignments i.e. True's become False's and vice versa. More on reddit.com
🌐 r/learnpython
16
5
September 11, 2024
🌐
freeCodeCamp
freecodecamp.org › news › python-do-while-loop-example
Python Do While – Loop Example
August 31, 2021 - For example, when you're writing a program that takes in input from users you may ask for only a positive number. The code will run at least once. If the number the user submits is negative, the loop will keep on running.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-do-while
Python Do While Loops - GeeksforGeeks
July 23, 2025 - In do while loop the statement runs at least once no matter whether the condition is false or true. ... In this example, we are going to print multiple of 2 using the do while loop.
🌐
Medium
medium.com › @BetterEverything › until-loops-and-do-while-loops-in-python-this-is-how-bfe43b22e6b4
Until Loops and Do While Loops in Python? This is how! | by Better Everything | Medium
August 13, 2024 - To make an Until loop we need to loop until a certain condition evaluates to True. To do that, we can choose between a for loop or a while loop to start repeating lines of code. In the loop we put an if-statement to check a condition.
🌐
Quora
quora.com › Does-Python-have-an-until-loop
Does Python have an until loop? - Quora
Answer (1 of 7): P̲y̲t̲h̲o̲n̲ ̲d̲o̲e̲s̲n̲’̲t̲ ̲h̲a̲v̲e̲ ̲a̲ ̲d̲e̲d̲i̲c̲a̲t̲e̲d̲ ̲`̲u̲nt̲i̲l̲`̲ ̲l̲o̲o̲p̲ ̲l̲i̲k̲e̲ ̲R̲u̲b̲y̲ ̲o̲r̲ ̲s̲o̲m̲e̲ ̲o̲t̲h̲e̲r̲ ̲l̲a̲n̲g̲u̲a̲g̲e̲s̲ ̲,̲ ̲b̲u̲t̲ ̲y̲o̲u̲ ̲c̲a̲n̲ ̲e̲a̲s̲i̲l̲y̲ ̲r̲e̲p̲l̲i̲c̲a̲t̲e̲ ̲t̲h̲e̲ ̲b̲e̲h̲av̲io̲r̲ ̲u̲si̲n̲g̲ ̲a̲ ̲`̲w̲h̲i̲l̲e̲`̲ ̲l̲o̲o̲...
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 - To emulate a "do-while" loop in Python, you can use a while loop with a True condition and strategically place a break statement. Here's an example: while True: # Execute your code here if not condition: break · In this structure, the loop executes at least once. The break statement is used to exit the loop if a certain condition is met, mimicking the behavior of a "do-while" loop. Consider a scenario where you want to repeatedly prompt a user for input until ...
🌐
Server Academy
serveracademy.com › blog › python-while-loop-tutorial
Python While Loop Tutorial - Server Academy
While infinite loops can be useful, they should be used with caution to avoid unintentional infinite runs. while True: print("This will run forever unless stopped manually.") This code will continue printing indefinitely until you manually interrupt ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
In below code, loop runs as long as the condition cnt < 3 is true. It increments the counter by 1 on each iteration and prints "Hello Geek" three times. ... If we want a block of code to execute infinite number of times then we can use the while ...
Published   1 month ago
🌐
Real Python
realpython.com › python-do-while
How Can You Emulate Do-While Loops in Python? – Real Python
August 2, 2022 - In this tutorial, you'll learn how to emulate do-while loops in Python. The most common technique to do this is to create an infinite while loop with a conditional statement that controls the loop and jumps out of it using a break statement.
🌐
Reddit
reddit.com › r/learnpython › how do you loop until correct input is given?
r/learnpython on Reddit: How do you loop until correct input is given?
February 25, 2022 -

I'm doing an assignment that requires I make a code that creates random numbers in a loop until I give a specific input. I just don't know how to get the loop to run while an input is requested. PLZ HELP!

EDIT:

To clarify the assignment:

Write a program that enters a number of positive integers.

The program ends when the user gives in a negative number.

a) Before the program ends, the largest number is printed.

b) Before the program ends, the smallest number is printed.

c) Before the program ends, the sum of the even numbers and the sum of the odd numbers are printed.

(I can do the a,b,c part no problem. It's the Program that creates the numbers i have problems with)

I asked my teacher what he meant by "a number of positive integers". He stated that the program should create numbers until the negative number is given.

EDIT 2:

I have concluded that I'm an idiot. It is the user who inputs the numbers. Thank you all for the help and not giving up with my dense skull :) (great community👍)

🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
In the above example, we have used a while loop to print the numbers from 1 to 3. The loop runs as long as the condition number <= 3 is True. ... The while loop evaluates condition, which is a boolean expression. If the condition is True, body of while loop is executed.
🌐
YoungWonks
youngwonks.com › blog › do-while-loop-python
What is a do while loop in Python? How do I create a while loop in Python? What is the difference between a for loop and a while loop in Python?
February 18, 2024 - If the condition is false, the break statement exits the loop. Otherwise, the loop continues. For example, if we want to ask the user to enter a number between 1 and 10 and repeat the question until ...
🌐
Codecademy
codecademy.com › forum_questions › 50f596b8981f64809b000105
I am confused, please explain until loops to me. | Codecademy
First I’ll give you the code, and then I’ll break it down. counter = 1 until counter == 11 puts counter counter = counter + 1 end · this is your counter. the name “counter” is arbitrary.
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - In this example, colors remains true as long as it has elements. Once you remove all the items with the .pop() method, colors becomes false, and the loop terminates. Getting user input from the command line is a common use case for while loops in Python. Consider the following loop that takes input using the built-in input() functions. The loop runs until you type the word "stop":
🌐
Texas Instruments
education.ti.com › en › resources › computer-science-foundations › do-while-loops
Python coding: Do While Loops | Texas Instruments
However, since this condition isn’t checked until after the loop has already been entered (and, specifically, after the step and action commands in this particular loop), the loop would still run one time and would display an output of -10 before the loop exited. (Do you see why?) This is a great example of the fact that post-test loops (such as Do While loops, modeled here with a While loop) always run at least one time.
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
February 24, 2023 - In this example, the while loop iterates over the numbers 1 through 10. The if statement checks whether the current value of i is even. If it is, the continue statement is executed, causing the loop to skip the current iteration and move on ...
🌐
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 Python, there is no dedicated do while conditional loop statement, and so this function is achieved by creating a logical code from the while loop, if statement, break and continue conditional statements.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-while-loop
Python While Loop - GeeksforGeeks
Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed.
Published   December 23, 2025