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
🌐
Coursera
coursera.org › tutorials › python-while-loop
How to Write and Use Python While Loops | Coursera
Since it checks that condition at the beginning, it may never run at all. To modify a while loop into a do while loop, add true after the keyword while so that the condition is always true to begin with.
Discussions

Repeat while loop?
Hello! So, Im trying to figure out how to repeat a while loop. I want my loop to restart completely, like if I’m making a game and I want a round two. I’ve tried looking online but it always confused me what is going on… anyone mind helping me out? More on discuss.python.org
🌐 discuss.python.org
0
October 28, 2021
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
Trouble understand 'While True'
i was looking throught the PySimpleGUI docs and i saw something i have seen a few times bfore in other Python code. The ‘while true’. This makes sense to me in most contexts where there is a pre-defined ‘break’. But this is what was defined in the docs while True: # The Event Loop event, ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
August 9, 2022
programming practices - while(true) and loop-breaking - anti-pattern? - Software Engineering Stack Exchange
Loops can become very involved and one or more clean breaks can be a lot easier on you, anyone else looking at your code, the optimizer, and the program's performance than elaborate if-statements and added variables. My usual approach is to set up a loop with something like the "while (true)" and ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
March 29, 2012
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
July 23, 2025 - A while loop in Python repeatedly executes a block of code as long as the specified condition evaluates to True. ... You use a break statement to exit the loop.
🌐
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 ...
🌐
Python.org
discuss.python.org › python help
Repeat while loop? - Python Help - Discussions on Python.org
October 28, 2021 - Hello! So, Im trying to figure out how to repeat a while loop. I want my loop to restart completely, like if I’m making a game and I want a round two. I’ve tried looking online but it always confused me what is going on……
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-break-statement
Python break statement - GeeksforGeeks
The break statement can be used within a for loop to exit the loop before it has iterated over all items, based on a specified condition. ... A while loop in Python repeatedly executes a block of code as long as a specified condition is True.
Published   4 days ago
🌐
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()

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
If we want a block of code to execute ... with the condition "True", which means that the loop will run infinitely until we break out of it using "break" keyword or some other logic....
Published   1 month ago
🌐
freeCodeCamp
forum.freecodecamp.org › python
Trouble understand 'While True' - Python - The freeCodeCamp Forum
August 9, 2022 - i was looking throught the PySimpleGUI docs and i saw something i have seen a few times bfore in other Python code. The ‘while true’. This makes sense to me in most contexts where there is a pre-defined ‘break’. But this is what was defined in the docs while True: # The Event Loop event, values = window.read() print(event, values) if event == sg.WIN_CLOSED or event == 'Exit': break to me, this means that the event loop will run until t...
🌐
Board Infinity
boardinfinity.com › blog › use-while-true-in-python
Use While True in Python | Board Infinity
August 13, 2025 - Here is an example of a basic "while ... will run forever!" indefinitely. To exit the loop, we can use a break statement, which will cause the loop to terminate when a certain condition is met....
🌐
Coursera
coursera.org › tutorials › python-break
How to Use Python Break | Coursera
1 2 3 4 5 6 7 8 9 10 # break statement for for loop for item in iterable: if some_condition: break # exit the loop # break statement for while loop while condition: # code block if some_condition: break # exit the loop · Write a program that counts from 1 to 100, printing each number. However, for multiples of 3, instead of printing the number, the program should print "Fizz". For multiples of 5, the program should print "Buzz". For numbers that are multiples of both 3 and 5, the program should print "FizzBuzz". The loop should exit after printing the number 100. PYTHON · 1 2 3 4 5 6 7 8 9 1
🌐
Quora
quora.com › What-can-you-do-if-you-cannot-break-out-of-an-infinite-while-loop-Python-Python-3-x-loops-while-loop-infinite-loop-development
What can you do if you cannot break out of an infinite while loop (Python, Python 3.x, loops, while loop, infinite loop, development)? - Quora
Answer: You can’t mean from within your code. There’s no case inside a while loop where you can’t use a break (or raise an exception, or exit the program). So presumably, what you’ve done is written a program with a tight loop that burns CPU and doesn’t yield to input processing anywhere.
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - Python lacks a built-in do-while loop, but you can emulate it using a while True loop with a break statement for conditional termination.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-while.html
While Loop
i = 0 while True: print(i) i += 1 if i >= 10: break 0 1 2 3 4 5 6 7 8 9
🌐
LearnDataSci
learndatasci.com › solutions › python-break
Python break statement: break for loops and while loops – LearnDataSci
Therefore, when relying on a break statement to end a while loop, you must ensure Python will execute your break command. Let's consider our previous example, where we wrote a script to find the first ten multiples of seven: # This is an infinite loop. Can you see why? while True: res = input("Enter the number 5: ") if res == 5: break
🌐
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:
🌐
Enki
enki.com › post › how-to-exit-a-loop-in-python
Enki | Blog - How to Exit a Loop in Python
The break statement helps us terminate or exit a loop before its natural end. It stops the loop immediately, bypassing any remaining iterations. This loop would normally run forever because while True sets an infinite loop. Here, break halts it once i reaches 5.
🌐
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): ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python while Loop (Infinite Loop, break, continue) | note.nkmk.me
August 18, 2023 - To stop the infinite loop using keyboard interrupt instead of setting break, you can catch the KeyboardInterrupt. try: while True: time.sleep(1) print('processing...') except KeyboardInterrupt: print('!!FINISH!!') ... 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. Try, except, else, finally in Python (Exception handling)