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
🌐
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 9
24
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 9
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: ")
Ending While True Loop Aug 17, 2023
r/learnpython
2y ago
¿Qué significa "while True"? Jan 10, 2021
r/learnpython
5y ago
While vs For? Apr 20, 2022
r/learnpython
4y ago
More results from reddit.com
Discussions

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
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
4
0
April 30, 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
5
0
June 15, 2024
Is using a while(true) loop bad coding practice?
I’m with you, I think it’s totally fine. I mean you could misuse it, but then that goes for anything, especially in programming. I wouldn’t bat an eye if a candidate did it in an interview. More on reddit.com
🌐 r/learnprogramming
124
391
May 13, 2021
🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... With the while loop we can execute a set of statements as long as a condition is true....
🌐
Board Infinity
boardinfinity.com › blog › use-while-true-in-python
while True in Python - How It Works & Best Practices
April 3, 2023 - In Python, while True creates an infinite loop - a loop that keeps running until something inside it tells it to stop. That "something" is almost always a break statement, a try-except block, or a condition that triggers an exit.
🌐
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.
🌐
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:...
Find elsewhere
🌐
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.
🌐
YouTube
youtube.com › watch
Python While True Loop Explained with 3 Easy Code Examples 2025 - YouTube
Learn how to use the Python while True loop in this beginner-friendly tutorial! 🚀 We'll break down what a while True loop is, why it's useful, and show you ...
Published   January 21, 2025
🌐
Readthedocs
pc-microbit-micropython.readthedocs.io › en › latest › lessons › while_True_loops.html
2. while True loops — PC-Microbit-Micropython
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 ...
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - The basic syntax of a while loop is shown below: ... In this syntax, condition is an expression that the loop evaluates for its truth value. If the condition is true, then the loop body runs.
🌐
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!

🌐
YouTube
youtube.com › imztech
Python For Beginners - How to use a While True Loop in Python - Lesson 17 With Examples - YouTube
Learn to code in small and manageable steps. Ideal for school students and beginners. Created by a qualified Teacher of Computer Science from the UK. Follow ...
Published   December 22, 2016
Views   7K
🌐
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 ...
🌐
OpenRouter
openrouter.ai › minimax › hailuo-2.3
Hailuo 2.3 - API Pricing & Benchmarks | OpenRouter
April 20, 2026 - Hailuo 2.3 is a video generation model from MiniMax. $0 per million input tokens, $0 per million output tokens. 0 token context window. Includes independent benchmarks from Artificial Analysis.
🌐
OpenAI Developers
developers.openai.com › api › docs › guides › migrate-to-responses
Migrate to the Responses API | OpenAI API
Stateful context: Use store: true to maintain state from turn to turn, preserving reasoning and tool context from turn-to-turn. Flexible inputs: Pass a string with input or a list of messages; use instructions for system-level guidance. Encrypted reasoning: Opt-out of statefulness while still ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_csv.html
pandas.read_csv — pandas 3.0.4 documentation
The C and pyarrow engines are faster, while the python engine is currently more feature-complete. Multithreading is currently only supported by the pyarrow engine. Some features of the “pyarrow” engine are unsupported or may not work correctly. ... Functions for converting values in specified columns. Keys can either be column labels or column indices. ... Values to consider as True in addition to case-insensitive variants of ‘True’.
🌐
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 a…
🌐
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.
🌐
Sololearn
sololearn.com › en › Discuss › 3060225 › what-is-the-difference-between-while-and-while-true-in-python
what is the difference between "while" and "while True " in ...
July 14, 2022 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.