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
🌐
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.
Discussions

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
0
August 9, 2022
What actually "while true" statement mean can someone pull me out this?
What actually "while true" statement mean can someone pull me out this · In practical terms, it will loop a code block, while a particular condition is True. Said condition may never be True, in which case you get an infinite loop, or you can set and test a variable so that you have a fixed ... More on discuss.python.org
🌐 discuss.python.org
0
0
April 30, 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
Is there a better alternative to "while true:" to run a script forever
I meant why do you want it to run forever? I imagined you maybe looking for a file to show up and you want to react to it? More on reddit.com
🌐 r/learnpython
13
2
July 12, 2018
🌐
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()

🌐
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....
🌐
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.
🌐
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.
🌐
freeCodeCamp
freecodecamp.org › news › python-while-loop-tutorial
Python While Loop Tutorial – While True Syntax Examples and Infinite Loops
November 13, 2020 - ... >>> while True: print(0) 0 ... The loop runs until CTRL + C is pressed, but Python also has a break statement that we can use directly in our code to stop this type of loop....
Find elsewhere
🌐
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:
🌐
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...
🌐
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
🌐
Python.org
discuss.python.org › python help
What actually "while true" statement mean can someone pull me out this? - Python Help - Discussions on Python.org
April 30, 2022 - What actually "while true" statement mean can someone pull me out this · In practical terms, it will loop a code block, while a particular condition is True. Said condition may never be True, in which case you get an infinite loop, or you can set and test a variable so that you have a fixed ...
🌐
TOOLSQA
toolsqa.com › python › python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
August 6, 2021 - The while loop in python runs until the "while" condition is satisfied. The "while true" loop in python runs without any conditions until the break statement executes inside 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 ...
🌐
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)
🌐
Medium
medium.com › code-85 › what-is-while-true-break-in-python-ac66abeef15c
What is While-True-Break in Python? | by Jonathan Hsu | Code 85 | Medium
October 31, 2021 - What is While-True-Break in Python? When you should create an infinite loop Iteration structures—code blocks that repeat—are an absolute fundamental tool. Previous articles have discussed …
🌐
Python
wiki.python.org › moin › WhileLoop
While loops - Python Wiki
while True: n = raw_input("Please enter 'hello':") if n.strip() == 'hello': break
🌐
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
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
When used with a loop, the else ... when no break occurs. For more on the try statement and exceptions, see Handling Exceptions. The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example: >>> while True: ...