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
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 ... More on teamtreehouse.com
🌐 teamtreehouse.com
2
October 29, 2017
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
How do I end a For or While loop without using break?
A for loop ends when it exhausts its iterable, and a while loop terminates when its condition is no longer met. If you were going to write while True: if some_variable == "some value": break #do stuff then instead you could write: while some_variable != "some value": #do stuff More on reddit.com
🌐 r/learnpython
4
4
March 19, 2022
🌐
AskPython
askpython.com › home › python while loop
Python while Loop - AskPython
February 16, 2023 - Python while loop is used to run a code block for specific number of times. We can use break and continue statements with while loop. The else block with while loop gets executed when the while loop terminates normally.
🌐
LearnPython.com
learnpython.com › blog › end-loop-python
How to End Loops in Python | LearnPython.com
December 16, 2021 - This linguistic tautology has been the mantra of many an underdog in a competition. It is also the first stop in our discussion on how to end a loop in Python. We can define an iterable to loop over with any of the data structures mentioned above. Alternatively, we can also use the built-in range(), which returns an immutable sequence.
🌐
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): ...
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - That’s why 2 isn’t printed. The control then returns to the loop header, where the condition is re-evaluated. The loop continues until number reaches 0, at which point it terminates as before. ... Python allows an optional else clause at the end of while loops.
🌐
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...
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true. ... Note: remember to increment i, or else the loop will continue forever.
🌐
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 - Exiting Loop on Condition: The ‘break’ statement enables the loop to be terminated based on a specific condition, such as when the desired task is completed or when a termination command like ‘exit’ is received. When mastering the art of ending a while loop in Python, it’s crucial to be mindful of common pitfalls that can lead to errors and inefficiencies.
🌐
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 ...
🌐
Altcademy
altcademy.com › blog › how-to-end-a-loop-in-python
How to end a loop in Python - Altcademy.com
September 2, 2023 - In Python, an infinite loop keeps running forever, unless it encounters a break statement or the program is forcefully stopped. Here's how you can create (and stop) an infinite loop: while True: user_input = input("Enter 'q' to quit: ") if user_input == 'q': break
🌐
Coursera
coursera.org › tutorials › python-break
How to Use Python Break | Coursera
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.
🌐
LearnDataSci
learndatasci.com › solutions › python-break
Python break statement: break for loops and while loops – LearnDataSci
strings = ['This ', 'is ', 'a ', 'list '] # iterate through each string in the list for string in strings: # iterate through each character in the string for char in string: print(char) if char == 'i': # if the character is equal to 'i', terminate the nested for loop print('break\n') break ... For any strings that contain an i, break exits our for char in string: loop. As this is our inner-most loop, Python then moves onto the next item in the for string in strings: loop. It's worth noting that if Python doesn't terminate while loops, they can loop endlessly.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - If you press ctrl + c in the running terminal (Mac) or command prompt (Windows cmd.exe), the while loop will be terminated, and the except clause will be executed. See the following article for exception handling.
🌐
Enki
enki.com › post › how-to-exit-a-loop-in-python
Enki | Blog - How to Exit a Loop in Python
Learn to manage loops effectively in Python using the break statement to exit for and while loops under specific conditions, optimizing code efficiency.
🌐
Real Python
realpython.com › python-break
How to Exit Loops Early With the Python break Keyword – Real Python
April 16, 2025 - However, while break exits the innermost loop entirely, ending any further iterations, continue skips the rest of the current iteration and moves on to the next one. Both keywords are valuable tools for exiting a loop iteration early when necessary. Python’s for and while loops have an else clause.
🌐
LabEx
labex.io › tutorials › python-how-to-use-break-statement-to-exit-a-while-loop-in-python-397695
How to use break statement to exit a while loop in Python | LabEx
The break statement in Python is used to exit a loop prematurely, even if the loop's condition is still True. When the break statement is encountered inside a loop, the loop immediately terminates, and the program control moves to the next statement ...
🌐
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 - Learn how to break out of nested loops in Python, exit specific loop levels using flags, functions, exceptions, and best practices for clean loop control
🌐
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 - This method allows you to manually stop the loop by pressing Ctrl+C. ... 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 ...
🌐
Altcademy
altcademy.com › blog › how-to-end-a-while-loop-in-python
How to end a while loop in Python - Altcademy.com
September 4, 2023 - Python while loop also supports an else statement that can be combined with the break statement for more control over your loop. The else block will execute if the loop has finished iterating (i.e., the while condition has become false), but ...