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: ") Answer from mopslik on reddit.com
🌐
Real Python
realpython.com β€Ί python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - If the condition is true, then the loop executes. Otherwise, it terminates. while loops are useful when the number of iterations is unknown, such as waiting for a condition to change or continuously processing user input.
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_while_loops.asp
Python While Loops
Python Examples Python Compiler ... a set of statements as long as a condition is true. ... Note: remember to increment i, or else the loop will continue forever....
People also ask

How Does a While Loop differ from a For Loop in Python?
A While Loop runs based on a condition and is ideal when the number of iterations is uncertain. In contrast, a for loop iterates over a sequence like a list or range, and is best used when the number of iterations is predefined or fixed.
🌐
theknowledgeacademy.com
theknowledgeacademy.com β€Ί blog β€Ί python-while-loop
Python While Loop: Everything You Should Know
Can I Use Functions Inside While Loops?
Yes, you can use functions inside While Loops. Functions help organise code, perform repeated tasks, and return values that can influence loop conditions. This makes your code cleaner, more efficient, and easier to debug, especially when complex operations are needed within each iteration of the loop
🌐
theknowledgeacademy.com
theknowledgeacademy.com β€Ί blog β€Ί python-while-loop
Python While Loop: Everything You Should Know
What is a Strange Loop?
A strange loop refers to a situation where a function or operation appears to reference itself in a way that creates a loop recursively, but it doesn't follow the traditional recursive paradigm. This can lead to complex structures and self-referencing patterns.
🌐
theknowledgeacademy.com
theknowledgeacademy.com β€Ί blog β€Ί python-while-loop
Python While Loop: Everything You Should Know
🌐
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.
🌐
TOOLSQA
toolsqa.com β€Ί python β€Ί python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
The while true in python is simple to implement. Instead of declaring any variable, applying conditions, and then incrementing them, write true inside the conditional brackets. ... The following code will run infinitely because "True" is always ...
🌐
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: ")
🌐
The Knowledge Academy
theknowledgeacademy.com β€Ί blog β€Ί python-while-loop
Python While Loop: Everything You Should Know
A Python While Loop with a continue statement keeps executing a code block as long as the specified condition remains true, skipping over the rest of the loop's body when the continue statement is encountered.
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί python-while-loop-tutorial
Python While Loop Tutorial – While True Syntax Examples and Infinite Loops
November 13, 2020 - If a break statement is found at any point during the execution of the loop, the loop stops immediately. Else, if break is not found, the loop continues its normal execution and it stops when the condition evaluates to False.
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me β€Ί home β€Ί python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - # 2 # !!FINISH!! ... If the condition in the while statement is always True, the loop will never end, and execution will repeat infinitely. In the following example, the Unix time is acquired using time.time(). The elapsed time is then measured ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
July 23, 2025 - 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. Its main uses include: Continuously prompt user input until ...
🌐
Board Infinity
boardinfinity.com β€Ί blog β€Ί use-while-true-in-python
Use While True in Python | Board Infinity
August 13, 2025 - One common use for "while True" loops are creating infinite scroll pages, where new content is loaded as the user scrolls down the page. In this case, the loop is used to check for new content continuously, and the break statement is used to ...
🌐
Coursera
coursera.org β€Ί tutorials β€Ί python-while-loop
How to Write and Use Python While Loops | Coursera
while loops continuously execute code for as long as the given condition is true. There is no do while loop in Python, but you can modify a while loop to achieve the same functionality.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί while-loop
Python while Loop (With Examples)
If the condition of a while loop always evaluates to True, the loop runs continuously, forming an infinite while loop.
🌐
Server Academy
serveracademy.com β€Ί blog β€Ί python-while-loop-tutorial
Python While Loop Tutorial - Server Academy
While infinite loops can be useful, ... 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 terminal...
🌐
Stanford CS
cs.stanford.edu β€Ί people β€Ί nick β€Ί py β€Ί python-while.html
While Loop
While Operation: Check the boolean test expression, 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.
🌐
TutorialsPoint
tutorialspoint.com β€Ί what-does-while-true-do-in-python
What Does while true do in Python?
The following Python code demonstrates ... boolean value evaluates to True every time, so it indicates that the loop will continue until something else breaks it....
🌐
Python
wiki.python.org β€Ί moin β€Ί WhileLoop
While loops - Python Wiki
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'.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-while-loop
Python While Loop - GeeksforGeeks
If it is True, the loop continues; if it is False, the loop terminates, and the program moves to the next statement after the loop. Here, the value of the condition is always True.
Published Β  December 23, 2025