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
🌐
freeCodeCamp
freecodecamp.org › news › python-do-while-loop-example
Python Do While – Loop Example
August 31, 2021 - There are cases where you would want your code to run at least one time, and that is where do while loops come in handy. 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. If it is positive, it will stop. Python does not have built-in functionality to explicitly create a do while loop like other languages.
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 21, 2023
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
🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
Python Examples Python Compiler ... Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true....
🌐
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̲...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-do-while
Python Do While Loops - GeeksforGeeks
July 23, 2025 - In Python, we can simulate the ... when the desired condition is met. Do while loop is a type of control looping statement that can run any statement until the condition statement ......
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.
🌐
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 - Here's how you can write a do-while loop in Python: The while True statement creates an infinite loop, which will run indefinitely unless we stop it. The if not conditional statements checks the opposite of the loop condition we want to use ...
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - while True in Python creates an infinite loop that continues until a break statement or external interruption occurs. Python lacks a built-in do-while loop, but you can emulate it using a while True loop with a break statement for conditional ...
🌐
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 Python, we use the while loop to repeat a block of code until a certain condition is met.
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
In Python, a while loop is used ... until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed. In below code, loop runs as long as the condition cnt < 3 is true.
Published   1 month ago
🌐
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 it, such as by pressing Ctrl + C in most terminals. An interesting feature in Python is that you can pair while with else.
🌐
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. You could call it “bacon.” However, a logical name like “counter” makes your code more readable. This is telling the computer that until the counter gets to 11, it should execute the instructions that follow. If the counter never gets to 11, you’ll have an infinite loop.
🌐
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.
🌐
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.
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
Prerequisites/helpful expertise: Basic knowledge of Python and programming concepts · While loops are control flow tools. Like for loops, they are used to iterate over a block of code. Unlike for loops, they will repeat that block of code for an unknown number of times until a specific condition is met. You’ll use while loops when you’re not sure how many times you need your code to repeat. You’ll use do while loops when you need it to repeat at least once.
🌐
Python
wiki.python.org › moin › ForLoop
ForLoop - Python Wiki
The for loop runs for a fixed amount of times, while the while loop runs until the loop condition changes. In this example, the condition is the boolean True which will never change, so it will run forever. If you've done any programming before, you have undoubtedly come across a for loop or ...
🌐
Python
wiki.python.org › moin › WhileLoop
While loops - Python Wiki
While loops, like the ForLoop, are used for repeating sections of code - but unlike a for loop, the while loop will not run n times, but until a defined condition is no longer met.