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
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true....
Discussions

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
while true statement looping in python - Stack Overflow
You have to modify the intb variable to something that waits for the user to input a correct value in the while statement. You can make the first lines a function, and call it back. If it enter the else, it might do the job in your case. ... w3schools.com/python/python_functions.asp if you ... More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
July 23, 2025 - In Python, loops allow you to repeat code blocks. The while loop runs as long as a given condition is true. Using while True creates an infinite loop that runs endlessly until stopped by a break statement or an external interruption.
🌐
W3Schools
w3schools.com › python › gloss_python_while.asp
Python While
Python Training ... With the while loop we can execute a set of statements as long as a condition is true. ... Note: remember to increment i, or else the loop will continue forever.
🌐
W3Schools
w3schools.io › python-while-loop
How to write While and do while loop with examples - w3schools
If the value is True, It executes code blocks, and Skip code execution, if the value is False · Code Blocks are multiple statement lines placed with indentation. first = 0 while first < 5: first += 1 print(first);
🌐
Readthedocs
pc-microbit-micropython.readthedocs.io › en › latest › lessons › while_True_loops.html
2. while True loops — PC-Microbit-Micropython - Read the Docs
2. while True loops · Previous Next · See: `<https://www.w3schools.com/python/python_while_loops.asp · While loops run a set of statements as long as a test condition is true. while True: loops run forever. Instead of using a condition that returns True or False, True is used in place of ...
🌐
W3Schools
w3schools.com › python › ref_keyword_while.asp
Python while Keyword
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Certificate Python Training ... The while keyword is used to create a while loop....
Find elsewhere
🌐
TOOLSQA
toolsqa.com › python › python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
August 6, 2021 - 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.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 ...
🌐
W3Schools
w3schoolsua.github.io › python › python_while_loops_en.html
Python While Loops. Lessons for beginners. W3Schools in English
Python Examples Python Compiler Python Exercises Python Quiz Python Bootcamp Python Certificate ... With the while loop we can execute a set of statements as long as a condition is true.
🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
In Python, we use a while loop to repeat a block of code until a certain condition is met. For example, number = 1 while number <= 3: print(number) number = number + 1 ... 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 ...
🌐
W3Schools
w3schools.com › python › gloss_python_while_else.asp
Python While Else
With the else statement we can run a block of code once when the condition no longer is true: Print a message once the condition is false: i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6") Try it Yourself » · Python While Tutorial · While · While Break · While Continue · While Else · ❮ Python Glossary · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS · BOOTCAMPS · CONTACT US · × · If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ·
🌐
Board Infinity
boardinfinity.com › blog › use-while-true-in-python
Use While True in Python | Board Infinity
August 13, 2025 - Learn how to use Python’s while True loop to create continuous iterations, handle break conditions, and build efficient loop-based programs.
🌐
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 - The general syntax for writing a while loop in Python looks like this: while condition: body of while loop containing code that does something ... You start the while loop by using the while keyword. Then, you add a condition which will be a Boolean expression. A Boolean expression is an expression that evaluates to either True or False.
🌐
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 › python-while-loop-tutorial
Python While Loop Tutorial – While True Syntax Examples and Infinite Loops
November 13, 2020 - Now that you know how while loops work and how to write them in Python, let's see how they work behind the scenes with some examples. Here we have a basic while loop that prints the value of i while i is less than 8 (i < 8): ... Iteration 1: initially, the value of i is 4, so the condition i < 8 evaluates to True and the loop starts to run.
🌐
W3Schools
w3schools.com › python › python_if_logical.asp
Python Logical Operators
a = 200 b = 33 c = 500 if a > b or a > c: print("At least one of the conditions is True") Try it Yourself » · The not keyword is a logical operator, and is used to reverse the result of the conditional statement. ... You can combine multiple logical operators in a single expression. Python evaluates not first, then and, then or.
🌐
TutorialsPoint
tutorialspoint.com › what-does-while-true-do-in-python
What Does while true do in Python?
April 4, 2023 - In summary, the "while true" loop is an effective tool for repeating tasks up until a predetermined condition is met. This loop structure is a key component of a Python programmer's toolkit, whether it is used in a simple script or a complex project.