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
🌐
Server Academy
serveracademy.com › blog › python-while-loop-tutorial
Python While Loop Tutorial - Server Academy
The while loop is a versatile and ... conditions. Here’s a recap of key points: Basic Usage: Use a while loop to repeat a block of code as long as a condition is true....
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
How to write a loop with conditions
Hello, I have to write a loop that prompts a user for their age in a program that outputs an admission price for a cinema ticket (depending on the user’s age) I have just started writing basic loops like this one below, but I don’t even know where to start regarding creating loops where ... More on discuss.python.org
🌐 discuss.python.org
0
January 11, 2022
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
Infinte while loop using try/except
hey y’all! I’m taking an online class called Cs50P, I thought I practiced using while loops + try/exceptions to the point of being confident using this structure. I’m running into an infinite loop when the exceptions are raised in the convert() function. More on discuss.python.org
🌐 discuss.python.org
0
June 15, 2024
🌐
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 set and test a variable so that you have a fixed ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
July 23, 2025 - This makes while True loops extremely ... the loop tells you to stop. Example 1: In this example, we use while True to create an infinite loop using the pass statement....
🌐
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 - And there is no set amount of times this will run and then stop, which means that for as long as the user doesn’t enter the string 'Python', the while loop will continue to execute. This is because the condition I set continues to evaluate to True.
🌐
TOOLSQA
toolsqa.com › python › python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
August 6, 2021 - To implement the while loop in Python, we first need to declare a variable in our code as follows (since initialization is not like the for loop): ... Now I want "Good Morning" to be printed 5 times. Therefore, the condition block will look as follows: ... The indented code will be the code I would like to execute when the condition returns True.
🌐
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: ")
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example: >>> while True: ...
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
This process repeats until the test expression evaluates to false. ... 1 2 3 4 5 numbers = [2, 4, 6, 8, 10] total = 0 for num in numbers: total += num print("The total is:", total) What will the interpreter display at the end of the fourth loop?
🌐
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 to become "False". Here is an example of a basic ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
In Python, a while loop is used ... 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
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-while.html
While Loop
Given that we have if/break to get out of the loop, it's possible to get rid of the test at the top of the loop entirely, relying on if/break to end the loop. We do this by writing the loop as while True:... Here is an example that uses while/True to go through the numbers 0..9.
🌐
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, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - For example, since non-zero numbers and non-empty strings are considered True, a statement like while 1: will create an infinite loop. Convert bool (True, False) and other types to each other in Python
🌐
Python.org
discuss.python.org › python help
How to write a loop with conditions - Python Help - Discussions on Python.org
January 11, 2022 - Hello, I have to write a loop that prompts a user for their age in a program that outputs an admission price for a cinema ticket (depending on the user’s age) I have just started writing basic loops like this one below,…
🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
For example, while True: user_input = input('Enter your name: ') # terminate the loop when user enters end if user_input == 'end': print(f'The loop is ended') break print(f'Hi {user_input}') ... Here, the condition of the while loop is always True. However, if the user enters end, the loop ...
🌐
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 ...
🌐
Python.org
discuss.python.org › python help
Infinte while loop using try/except - Python Help - Discussions on Python.org
June 15, 2024 - hey y’all! I’m taking an online class called Cs50P, I thought I practiced using while loops + try/exceptions to the point of being confident using this structure. I’m running into an infinite loop when the exceptions are raised in the convert() function.
🌐
freeCodeCamp
freecodecamp.org › news › python-while-loop-tutorial
Python While Loop Tutorial – While True Syntax Examples and Infinite Loops
November 13, 2020 - 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.