while True means loop forever. The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually! Most languages you're likely to encounter have equivalent idioms.

Note that most languages usually have some mechanism for breaking out of the loop early. In the case of Python it's the break statement in the cmd == 'e' case of the sample in your question.

Answer from Richard Cook on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_while_loops.asp
Python While Loops
With the break statement we can stop the loop even if the while condition is true: ... Note: The else block will NOT be executed if the loop is stopped by a break statement. ... If you want to use W3Schools services as an educational institution, ...
Discussions

Can someone explain what this `while True` function is actually checking?
A while loop runs while a condition is true. True is always true, so it will run until something causes it to break (e.g. a break statement, program crash, etc.) For comparison, the first loop in the code you posted could be rewritten without an infinite loop as: age = input("Enter your age: ") while not age.isdecimal(): age = input("Please enter a number for your age: ") More on reddit.com
๐ŸŒ r/learnpython
14
17
December 13, 2023
What actually "while true" statement mean can someone pull me out this?
What actually "while true" statement mean can someone pull me out this ยท In practical terms, it will loop a code block, while a particular condition is True. Said condition may never be True, in which case you get an infinite loop, or you can set and test a variable so that you have a fixed ... More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
April 30, 2022
sorry to ask such a silly question but what does 'while True:' actually mean?
while will always evaluate whatever comes behind it. For instance i =0 while i < 10: print(i) i = i+ 1 Here i <10 is evaluated to either be true or false. This will happen each iteration. i = 0 , True i= 1, True i= 2, True Etc, untill: i=10, False => break loop The code will continue untill it evaluates to false. while True kind of hacks it: True will always evaluate to True. While looks at it and thinks: hey this is true! So it always continues. While true isn't commonly used, but when it is it's commonly used with a break statement. (Or interrupted by ctrl + c). While False will never do anything in the loop as you stated. It checks to see if False is True. But it's never true, so it doesnt execute the code in the while loop. (Sorry fod bas formatting, mobile) More on reddit.com
๐ŸŒ r/learnpython
71
76
November 14, 2023
Is using while True loops good?
Having a proper end condition for the while loop makes it more readable, and easier to understand. More on reddit.com
๐ŸŒ r/learnpython
19
10
December 3, 2022
๐ŸŒ
Real Python
realpython.com โ€บ python-while-loop
Python while Loops: Repeating Tasks Conditionally โ€“ Real Python
March 3, 2025 - If you come from languages like C, C++, Java, or JavaScript, then you may be wondering where Pythonโ€™s do-while loop is. The bad news is that Python doesnโ€™t have one. The good news is that you can emulate it using a while loop with a break statement. Consider the following example, which takes user input in a loop: ... >>> while True: ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
July 23, 2025 - A while loop in Python repeatedly executes a block of code as long as the specified condition evaluates to True. ... You use a break statement to exit the loop. An exception or program exit occurs inside the loop.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ can someone explain what this `while true` function is actually checking?
r/learnpython on Reddit: Can someone explain what this `while True` function is actually checking?
December 13, 2023 -

https://pastebin.com/NWkKQc1P

It's from Automate the Boring Stuff. I tried running it through the python tutor and it didn't clarify. Is the basic point that there actually isn't anything it's checking to be True, so it's an infinite loop until you trigger the `break`?

PS I figure this is something simple from much earlier that I didn't internalize. I plan to go through all the basic curriculum again to make sure there aren't any gaps in super basic knowledge.

Top answer
1 of 8
23
A while loop runs while a condition is true. True is always true, so it will run until something causes it to break (e.g. a break statement, program crash, etc.) For comparison, the first loop in the code you posted could be rewritten without an infinite loop as: age = input("Enter your age: ") while not age.isdecimal(): age = input("Please enter a number for your age: ")
2 of 8
9
Correct; this is just a way to start an infinite loop that you intend to break with some condition/break statement later on. Mostly used for starting/running an application that you don't want to close down without user intent (clicking an exit/quit button in a UI or entering "quit", "exit", etc from the command line. It *isn't* a great construct to use when you want something that has solidly defined criteria to repeat until those criteria are met. As mopslik pointed out, you would be better served in those examples to actually use the defined criteria in those as your loop conditions since you're not at risk of just sticking the user in an infinite loop if you forget to write your break statement somewhere. You, also, don't have to write so many lines to accomplish the same goal. ``` password = "" while not password.isalnum(): password = input('Select a new password (alphanumeric only') print("Password is good") ``` You do not have to print a line and then call input(), either. Just put the message you want displayed into the parens for the function call: input("Enter your age: ")
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ while-loops-in-python-while-true-loop-statement-example
While Loops in Python โ€“ While True Loop Statement Example
July 19, 2022 - If the condition evaluates to True, ... the loop's body and continue to run the code while the condition remains True. It will keep executing the desired set of code statements until that condition is no longer True.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-while.html
While Loop
While Operation: Check the boolean ... if it is True, run all the "body" lines inside the loop from top to bottom. Then loop back to the top, check the test again, and so on. When the test is False, exit the loop, running continues on the first line after the body lines.
Find elsewhere
๐ŸŒ
TOOLSQA
toolsqa.com โ€บ python โ€บ python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
August 6, 2021 - Python "Do While" loops. The while loop in python is a way to run a code block until the condition returns true repeatedly. Unlike the "for" loop in python, the while loop does not initialize or increment the variable value automatically.
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ WhileLoop
While loops - Python Wiki
April 10, 2017 - As you can see, this compacts the whole thing into a piece of code managed entirely by the while loop. Having True as a condition ensures that the code runs until it's broken by n.strip() equaling 'hello'.
๐ŸŒ
Coursera
coursera.org โ€บ tutorials โ€บ python-while-loop
How to Write and Use Python While Loops | Coursera
Since it checks that condition at the beginning, it may never run at all. To modify a while loop into a do while loop, add true after the keyword while so that the condition is always true to begin with.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-do-while-loop-example
Python Do While โ€“ Loop Example
August 31, 2021 - The while loop, on the other hand, doesn't run at least once and may in fact never run. It runs when and only when the condition is met. So, let's say we have an example where we want a line of code to run at least once. secret_word = "python" counter = 0 while True: word = input("Enter the secret word: ").lower() counter = counter + 1 if word == secret_word: break if word != secret_word and counter > 7: break
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
What actually "while true" statement mean can someone pull me out this? - Python Help - Discussions on Python.org
April 30, 2022 - What actually "while true" statement mean can someone pull me out this ยท In practical terms, it will loop a code block, while a particular condition is True. Said condition may never be True, in which case you get an infinite loop, or you can ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ sorry to ask such a silly question but what does 'while true:' actually mean?
r/learnpython on Reddit: sorry to ask such a silly question but what does 'while True:' actually mean?
November 14, 2023 -

what does the True refer to?

eg if i write:

while True: 
    print("hi")

i know that "hi" will be repeated infinitely, but what is it thats True thats making "hi" get printed?

also, whatever it is thats True, im assuming its always true, so is that why if i typed 'while False', none of the code below would ever run?

sorry if this is a stupid question

edit: also, besides adding an if statement, is there anything else that would break this infinite while loop?

and how would i break the loop, lets say after "hi" has been printed 10 times, using an if statement or whatever else there is that can break it. thanks!

๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ use-while-true-in-python
Use While True in Python | Board Infinity
August 13, 2025 - To use a "while True" loop in Python, you must first define a condition that will eventually evaluate to "False" for the loop to terminate. This is typically done using a Boolean variable initially set to "True," then modified within the loop ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ loops-in-python
Loops in Python - GeeksforGeeks
Code given below uses a 'while' loop with the condition "True", which means that the loop will run infinitely until we break out of it using "break" keyword or some other logic. ... Note: It is suggested not to use this type of loop as it is ...
Published ย  4 days ago
๐ŸŒ
Quora
quora.com โ€บ What-does-while-true-do-in-python
What does 'while true' do in python? - Quora
Answer (1 of 12): Thanks for A2A While True means loop for ever. While loops, are used for repeating a section of code until the defined condition is met. [code]q = 0 while q
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-while-loop-tutorial-do-while-true-example-statement
Python While Loop Tutorial โ€“ Do While True Example Statement
August 24, 2020 - The while loop will check the condition every time, and if it returns "true" it will execute the instructions within the loop. Before we start writing code, let's look at the flowchart to see how it works.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ what-does-while-true-do-in-python
What Does while true do in Python?
April 4, 2023 - This boolean value evaluates to True every time, so it indicates that the loop will continue until something else breaks it. Any repeatable code can be placed inside the loop. So here are a few basic examples of how a "while True" statement ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ while-loop
Python while Loop (With Examples)
while True: user_input = input("Enter password: ") # terminate the loop when user enters exit if user_input == 'exit': print(f'Status: Entry Rejected') break print(f'Status: Entry Allowed') ... Before we wrap up, letโ€™s put your knowledge of Python while loop to the test!