Usually, this is done by returning some value that lets you decide whether or not you want to stop the while loop (i.e. whether some condition is true or false):

def stopIfZero(a):
    if int(a) == 0:
        return True
    else:
        print('Continue')
        return False

while True:
    if stopIfZero(input('Number: ')):
        break
Answer from JCOC611 on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_keyword_break.asp
Python break Keyword
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... The break keyword is used to break out a for loop, or a while loop....
🌐
Reddit
reddit.com › r/learnpython › use of break in python
r/learnpython on Reddit: Use of break in Python
May 11, 2019 -

Quite a number of my fellow teachers have been saying that we should NEVER use breaks in loops. However in our examination there is often a need to validate an input e.g.

while True:
    ID = input("What is the cow's ID code?")
    if len(ID) == 3:
        CowID.append(ID)
        break
    else:
        print("Cow ID has been entered wrongly.")

The break works perfectly well in Python, but it has been suggested to me that I avoid using such constructs. What are your thoughts on this and does anyone have credible sources one way or another? In the age of the Internet my students will quickly find break and I would need a very strong argument as to why they don't use it. Equally, if I go against these other teachers I will need credible evidence as to why I am doing it this way.

Your thoughts, arguments and ideas are very much appreciated. This debate has been rumbling on already for over a month and I would like to get a good answer before I plan next year's lessons.

People also ask

Is there a break function in Python?
Yes. The break statement in Python is written as "break". It must be positioned in accordance with Python's syntactical structure, such that it is properly indented if it is inside of a loop, class, or function.
🌐
study.com
study.com › computer science courses › computer science 113: programming in python
Break Statement in Python | Loops & Examples | Study.com
How do you write a break in Python?
A break statement can be implemented in Python with the word "break". For example, if you wanted to exit the loop if n became 10, the following conditional statement, with appropriate indentation, would accomplish this task: · if n == 10: · break
🌐
study.com
study.com › computer science courses › computer science 113: programming in python
Break Statement in Python | Loops & Examples | Study.com
What is the break statement in Python?
The break statement in Python is an intentional exit from the loop that is currently running. This is useful when you wish to break out of a loop prematurely if some condition is met.
🌐
study.com
study.com › computer science courses › computer science 113: programming in python
Break Statement in Python | Loops & Examples | Study.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-break-statement
Python Break Statement - GeeksforGeeks
When the value 5 is found, the message "5 found!" is printed and found variable is set to True and break exits the inner loop immediately. Loops in Python help automate repetitive tasks, but sometimes you may need to exit a loop, skip an iteration, or alter the normal flow of execution.
Published   June 5, 2026
🌐
Coursera
coursera.org › tutorials › python-break
How to Use Python Break | Coursera
In Python, break allows you to exit a loop when an external condition is met. Normal program execution resumes at the next statement. You can use a break statement with both for loops and while loops.
🌐
Tutorialspoint
tutorialspoint.com › python › python_break_statement.htm
Python - break Statement
Python break statement is used to terminate the current loop and resumes execution at the next statement, just like the traditional break statement in C. The most common use for Python break statement is when some external condition is triggered
🌐
Study.com
study.com › computer science courses › computer science 113: programming in python
Break Statement in Python | Loops & Examples | Study.com
The break statement is an incredibly useful command for exiting loops, and is expressed in Python as the keyword ''break''. Breaking is essential in while True loops in order to exit the infinite looping, and it is also the only way of prematurely ...
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › break-statement
Python Break Statement: Syntax, Usage, and Practical Examples
The break statement only exits the innermost loop where it appears. ... Here, the inner loop is broken each time j == 1, but the outer loop continues as expected. One practical use case for the Python break statement is to exit infinite loops that would otherwise run forever.
🌐
Python
docs.python.org › 2.0 › ref › break.html
6.9 The break statement
break may only occur syntactically nested in a for or while loop, but not nested in a function or class definition within that loop.
🌐
Simplilearn
simplilearn.com › home › resources › software development › break in python: a step by step tutorial to break statement
Break in Python: A Step by Step Tutorial to Break Statement
February 15, 2026 - The break statement is used to control the sequence of the loop. Explore more about syntax, flowchart, and how to use break in python. Start learning now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Python Tutorial
pythontutorial.net › home › python basics › python break
Python break
March 26, 2025 - Use the Python break statement to terminate a for loop or a while loop prematurely.
🌐
Unstop
unstop.com › home › blog › python break statement & uses explained (with code examples)
Python Break Statement & Uses Explained (With Code Examples)
November 28, 2024 - The Python program example below illustrates the use of the break statement inside a while loop. ... #Checking user input for a specific value correct_number = 7 # The number to guess while True: user_input = int(input("Guess the number: ")) if user_input == correct_number: # External condition print("Congratulations! You guessed it right.") break # Break command ends the current loop else: print("Try again!") print("End of game.")
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › break in python
Break Statement in Python: How and When to Use It
May 14, 2025 - The break statement in Python is used to exit a loop before it has processed all its iterations. When a break is encountered inside a loop, it immediately stops the loop's execution, and control is transferred to the next statement after the loop.
🌐
Flexiple
flexiple.com › python › python-break-continue
How to use Python Break & Continue statements? - Flexiple
March 11, 2022 - This is because most use cases would require you to break the flow only when a particular condition is met. Note: Although Python break exits the loops, it only exits the loop it is placed in, so while using a nested loop only the loop containing the break statement would be exited.
🌐
WsCube Tech
wscubetech.com › resources › python › break-statement
Break Statement in Python: Uses, Working, Examples
October 1, 2025 - Understand the Python break statement, its uses, how it works, best practices, and examples to control loops efficiently in your Python programs.
🌐
freeCodeCamp
freecodecamp.org › news › python-break-statement-tutorial
Python Break Statement – How to Break Out of a For Loop in Python
April 16, 2024 - From the above examples, you learned how to use the break statement to terminate for and while loops in Python.
🌐
IONOS
ionos.com › digital guide › websites › web development › python break continue
How to use Python break and continue - IONOS
July 13, 2023 - Python break and Python continue allow you to terminate or interrupt a loop. These commands often work in con­junc­tion with an “if” statement.
🌐
Codecademy
codecademy.com › docs › python › keywords › break
Python | Keywords | break | Codecademy
June 17, 2025 - The break keyword in Python is used to exit a loop immediately.