just indent your code correctly:

def determine_period(universe_array):
    period=0
    tmp=universe_array
    while True:
        tmp=apply_rules(tmp)#aplly_rules is a another function
        period+=1
        if numpy.array_equal(tmp,universe_array) is True:
            return period
        if period>12:  #i wrote this line to stop it..but seems its doesnt work....help..
            return 0
        else:   
            return period

You need to understand that the break statement in your example will exit the infinite loop you've created with while True. So when the break condition is True, the program will quit the infinite loop and continue to the next indented block. Since there is no following block in your code, the function ends and don't return anything. So I've fixed your code by replacing the break statement by a return statement.

Following your idea to use an infinite loop, this is the best way to write it:

def determine_period(universe_array):
    period=0
    tmp=universe_array
    while True:
        tmp=apply_rules(tmp)#aplly_rules is a another function
        period+=1
        if numpy.array_equal(tmp,universe_array) is True:
            break
        if period>12:  #i wrote this line to stop it..but seems its doesnt work....help..
            period = 0
            break

    return period
Answer from Mapad on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. With the break statement we can stop the loop even if the while condition is true:
Discussions

python - How can I stop a While loop? - Stack Overflow
I wrote a while loop in a function, but don't know how to stop it. When it doesn't meet its final condition, the loop just go for ever. How can I stop it? def determine_period(universe_array): ... More on stackoverflow.com
🌐 stackoverflow.com
Can't get while loop to stop
I am making a number guessing game, and I have a while loop over the whole thing. The problem is, I can’t get it to stop when I want it to. import random import sys import time ynChoice = 'x' global runGTN runGTN = True while runGTN == True: #the loop typing_speed = 300 #wpm def printSlow(*t): ... More on discuss.python.org
🌐 discuss.python.org
11
0
May 6, 2024
How can I break out of a while loop immediately and at any point during the while loop.
Literally, this is what the break statement does. More on reddit.com
🌐 r/learnpython
32
0
June 23, 2023
Ending While True Loop
You use list as a variable name. This masks the list constructor which can cause weird problems. I changed list to l everywhere. Don't know if using list caused problems. You are changing the list you are iterating over in the for loop. Bad idea. Don't know if doing that causes problems, but it's a bad idea. You use while list != None: in an attempt to check if the new list is empty. Trouble is, an empty list looks like [] and never equals None. Use python "truthiness": while list: More on reddit.com
🌐 r/learnpython
18
3
August 17, 2023
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
July 10, 2026 - Python allows an optional else clause at the end of while loops. The syntax is shown below: ... The code under the else clause will run only if the while loop terminates naturally without encountering a break statement.
🌐
Python.org
discuss.python.org › python help
Can't get while loop to stop - Python Help - Discussions on Python.org
May 6, 2024 - I am making a number guessing game, and I have a while loop over the whole thing. The problem is, I can’t get it to stop when I want it to. import random import sys import time ynChoice = 'x' global runGTN runGTN = True while runGTN == True: #the loop typing_speed = 300 #wpm def printSlow(*t): for l in t: sys.stdout.write(l) sys.stdout.flush() time.sleep(random.random()*10.0/typing_speed) print() def confirmChoice(ynChoice): ...
🌐
Finxter
blog.finxter.com › home › learn python blog › how to stop a while loop in python
How to Stop a While Loop in Python - Be on the Right Side of Change
September 28, 2022 - You can also watch my explainer video as you go through the article: The most Pythonic way to end a while loop is to use the while condition that follows immediately after the keyword while and before the colon such as while <condition>: <body>. ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - 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 and used to set the ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › how can i break out of a while loop immediately and at any point during the while loop.
r/learnpython on Reddit: How can I break out of a while loop immediately and at any point during the while loop.
June 23, 2023 -

I have a long while loop, it has a lot of code in it and a lot of delays.

I want to break out of the loop when a condition is met but I need to break out of it instantly. The only thing I can think of, is to print if statements constantly through the loop, checking if the condition is true, but this seems a little silly because it would have literally 100s of break statements.

Is there any better way to do this without typing break statements after every single line of code, that seems impractical because there's 100s of lines of code in the while loop, it takes around 10 minutes to finish and I need it to break instantly

🌐
Reddit
reddit.com › r/learnpython › ending while true loop
r/learnpython on Reddit: Ending While True Loop
August 17, 2023 -

I'm doing a CS50p project on making a grocery list. The only issue I'm having is once the list prints, I need the program to end. No matter where I break, it either doesn't stop the program or does stop it but bugs something else.
This is what I have:

def main():
list = []
while True:
    try:
        item = input()
        list.insert(0, item)
        continue
    except EOFError:
        list.sort()
        while list != None:
            for word in list:
                x = list.count(word)
                if x != 0:
                    print(str(x) + " " + str.upper(word), sep=" ")
                    list = [i for i in list if i!=word]
                else:
                    break
        break

main()

🌐
Sololearn
sololearn.com › en › Discuss › 1802484 › how-to-stop-python-while-loop
how to stop python while loop
May 15, 2019 - 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.
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-exit-a-while-loop-with-a-break-statement-in-Python.php
How to Exit a While Loop with a Break Statement in Python
However, since we place a break statement in the while loop, it isn't infinite and the program exits the while loop when the count reaches 25. break is a reserved keyword in Python.
🌐
BlueVPS
bluevps.com › blog › how to end a loop in python? (python exit for loop)
How to End a Loop in Python?
September 9, 2025 - A practical workaround is to use a flag variable that signals when a condition has been met, allowing the outer loop to stop cleanly. ... Placing loop logic inside a function gives you more control.
🌐
Quora
quora.com › Is-it-possible-to-stop-an-infinite-loop-in-Python-without-using-break-or-return-statements-If-so-what-alternative-methods-can-be-used
Is it possible to stop an infinite loop in Python without using break or return statements? If so, what alternative methods can be used? - Quora
Answer (1 of 2): Only two things can break that loop: 1. Keyboard interrupt - You can stop the execution of the program by manually interrupting it with a keyboard interrupt (Ctrl+C) 2. Kill the process - in Windows you can do from the task manager. In Linux you can use the kill command.
🌐
Pierian Training
pieriantraining.com › home › python tutorial: how to stop an infinite loop in python
Python Tutorial: How to stop an infinite loop in Python - Pierian Training
April 12, 2023 - One of the simplest ways to stop an infinite loop in Python is by using a keyboard interrupt. This method involves pressing the “Ctrl + C” keys on your keyboard while the program is running.
🌐
Quora
quora.com › How-can-you-create-a-while-loop-without-using-the-continue-or-break-statements-only-with-if-conditions-and-for-loops
How to create a while loop without using the 'continue' or 'break' statements, only with 'if' conditions and 'for' loops - Quora
Answer (1 of 2): There is some sort of misconception here. No while loop is forced to use continue or break. It’s always possible to avoid break using a boolean variable (aka flag) that you test for in the while statement’s condition. You can always avoid continue as well (using an appropriate ...
🌐
Medium
sibabalwesinyaniso.medium.com › mastering-while-loops-break-and-continue-in-python-controlling-program-flow-efficiently-e3a7512b3710
Mastering While Loops, Break, and Continue in Python — Controlling Program Flow Efficiently | by Sibabalwe Sinyaniso | Medium
February 4, 2025 - password = "" while password != "python123": password = input("Enter the password: ") print("Access granted!") This loop keeps asking for the correct password until the user enters "python123". The break statement immediately exits a loop, regardless of its condition.
🌐
Team Treehouse
teamtreehouse.com › community › how-to-stop-the-while-loop
how to stop the while loop (Example) | Treehouse Community
October 29, 2017 - The python 'break' statement is used to break out of a loop. Or you could use a boolean value outside of the loop like this. keepLooping = True while keepLooping: # Loop statements here keepLooping = False ... right, I would use a break statement at the end, but how do I ensure that the loop ran enough times to delete all instances of a vowel in a word before I break?
🌐
Quora
quora.com › How-can-a-while-loop-in-Python-be-used-to-terminate-when-a-specific-condition-is-met
How can a while loop in Python be used to terminate when a specific condition is met? - Quora
Answer (1 of 5): A while loop terminates as soon as a specific condition is not met. So, to make it terminate as soon as a specific condition is met, you just reverse the sense of that condition—e.g., by throwing a not on it. [code]while not condition_is_met(): do_stuff() [/code]Alternatively,...
🌐
Quora
quora.com › How-can-I-break-out-of-the-innermost-while-loop-while-True-on-Python-without-breaking-the-outer-while-loops
How to break out of the innermost while loop (while True) on Python without breaking the outer while loops - Quora
Answer (1 of 3): Hello! What will Ramesh Kummar's program achieve? For each value of the number i (ranging from 0 to 4 ) we should print the number i and then let J vary by values ​​0 through 3. And also print all the j values. We have here an iteration of i values ​​and each sequence ...