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
Discussions

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
0
0
May 6, 2024
how to stop the while loop
Andrew McLane is having issues with: So I added a while loop so that the loop could run for words that had multiple vowels, and multiple of the same vowels. However, I can't figure ... More on teamtreehouse.com
🌐 teamtreehouse.com
2
October 29, 2017
Unable to quit infinite while loop in idle 3.12.0 (64 bit) with keyboard interrupt
Hello I am learning python, in IDLE when i write # infinite while loop i = 1 while i < 2: print(i) it produces an infinite while loop . But for some reason I am unable to use the keyboard interrupt (ctrl + C) Id… More on discuss.python.org
🌐 discuss.python.org
0
0
December 10, 2023
I'm not able to exit my while loop...
Christopher Morris is having issues with: so I am utilizing the following code: name = input("What's your name? ") question = input("Do you understand Python while loops?... More on teamtreehouse.com
🌐 teamtreehouse.com
2
August 28, 2018
🌐
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:
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - In this tutorial, you'll learn about indefinite iteration using the Python while loop. You'll be able to construct basic and complex while loops, interrupt loop execution with break and continue, use the else clause with a while loop, and deal with infinite loops.
🌐
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): ...
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
However, we're also using an if ... reached the halfway point, stopping loop." and then immediately exit the loop using the break statement....
🌐
Team Treehouse
teamtreehouse.com › community › how-to-stop-the-while-loop
how to stop the while loop (Example) | Treehouse Community
October 29, 2017 - ... def disemvowel(word): while ... word.remove("U") except ValueError: pass return word ... The python 'break' statement is used to break out of a loop....
Find elsewhere
🌐
Coursera
coursera.org › tutorials › python-break
How to Use Python Break | Coursera
February 24, 2023 - When working with loops, remember that indentation tells Python which statements are inside the loop and which are outside the loop. Your break statement should follow your if statement and be indented.
🌐
Python.org
discuss.python.org › python help
Unable to quit infinite while loop in idle 3.12.0 (64 bit) with keyboard interrupt - Python Help - Discussions on Python.org
December 10, 2023 - Hello I am learning python, in IDLE when i write # infinite while loop i = 1 while i < 2: print(i) it produces an infinite while loop . But for some reason I am unable to use the keyboard interrupt (ctrl + C) Id…
🌐
LearnDataSci
learndatasci.com › solutions › python-break
Python break statement: break for loops and while loops – LearnDataSci
Can you see why? while True: res = input("Enter the number 5: ") try: res = int(res) except: pass if res == 5: print("Thanks!") break ... It can be hard to spot when one of your background processes gets caught in an infinite loop. You're not breaking any of Python's rules by getting stuck in a loop, so there are often not any helpful error messages to let you know what you've done wrong.
🌐
Enki
enki.com › post › how-to-exit-a-loop-in-python
Enki | Blog - How to Exit a Loop in Python
This loop would normally run forever because while True sets an infinite loop. Here, break halts it once i reaches 5. This prevents unnecessary iterations, saving resources. Using break improves performance by cutting off loop execution as soon as our conditions are met. It reduces unnecessary computation and makes our code more efficient. A for loop is designed to iterate over sequences. But there are times when we want to stop it early.
🌐
Team Treehouse
teamtreehouse.com › community › im-not-able-to-exit-my-while-loop
I'm not able to exit my while loop... (Example) | Treehouse Community
August 28, 2018 - {}, (Yes/No)".format(name) while True: answer = input(question) if answer.lower() == 'yes': print("That's great, Python is a great language {}".format(name)) break elif answer.lower() == 'no': print("You must learn python, it's a great language {}".format(name)) break else: print("You didn't enter correct answer {}, try again".format(name)) continue · The loop will break whether the answer is a yes or a no, otherwise it will indicate to the user that the answer is not what is expected and it will keep looping until a 'yes' or a 'no' is received.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-break-statement
Python break statement - GeeksforGeeks
The break statement in Python is used to exit or "break" out of a loop (either for or while loop) prematurely, before the loop has iterated through all its items or reached its condition.
Published   1 week ago
🌐
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
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,...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-kill-a-while-loop-with-a-keystroke-in-python
How to Kill a While Loop with a Keystroke in Python? - GeeksforGeeks
July 23, 2025 - import time try: num = 11 while True: if num % 2 == 0: break print(num) num = num + 2 time.sleep(1) # Wait 1 second before next iteration except KeyboardInterrupt: pass print("Continuing with the program") ... This approach allows the user to press a specific key (like q) to exit the loop. But to implement this in our code we need to first install the keyboard library using this command: ... import keyboard def main_loop(): while True: print("Working...") # Press 'q' to exit if keyboard.is_pressed('q'): print("Loop terminated by user.") break if __name__ == "__main__": main_loop()
🌐
PythonHow
pythonhow.com › how › break-a-while-loop
Here is how to break a while loop in Python
import random # This loop will run forever unless we break it while True: # Generate a random int between 1 and 10 random_integer = random.randint(1, 10) print(random_integer) # Stop the loop if the random int is 5 if random_integer == 5: break ... The output will consist of a series of numbers until number 5 is picked by the randint method. ... The while True part is the condition. It checks if True is True. That is always the case. John is always John. So the while loop will run eternally unless it encounters a break statement. You could also rewrite the above Python code to this and it would do the same thing:
🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
while True: user_input = input("Enter password: ") # terminate the loop when user enters exit if user_input == 'exit': print(f'Status: Entry Rejected') break print(f'Status: Entry Allowed') ... Before we wrap up, let’s put your knowledge of Python while loop to the test!
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-break-continue-and-pass-statements-when-working-with-loops-in-python-3
How to Break Out of Multiple Loops in Python | DigitalOcean
August 7, 2025 - For instance, you might encounter a situation where you need to exit a loop prematurely, skip the current iteration, or simply have a placeholder for future code. Python provides three powerful statements to handle these cases: break, continue, and pass. The break statement allows you to exit ...
🌐
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…
🌐
ImportPython
importpython.com › home › mastering how to end a while loop in python
How To End A While Loop In Python: Ending While Loops Like a Pro
March 14, 2024 - This point comes when count holds the value of 5 or more the condition count < 5 is converted to false, and the loop stops to be executed further. Efficiency and absence of mistakes are the fundamental idea of a nice while loop in Python. On the one hand, the main rule of while loops is the comprehension of each element, and, on the other hand, those rules should be followed.