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

python - How can I stop a While loop? - Stack Overflow
You need to understand that the ... 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 ... More on stackoverflow.com
🌐 stackoverflow.com
How to write a loop with conditions
Hello, I have to write a loop that prompts a user for their age in a program that outputs an admission price for a cinema ticket (depending on the user’s age) I have just started writing basic loops like this one below, but I don’t even know where to start regarding creating loops where ... More on discuss.python.org
🌐 discuss.python.org
0
January 11, 2022
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
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
May 6, 2024
🌐
Altcademy
altcademy.com › blog › how-to-end-a-loop-in-python
How to end a loop in Python
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
🌐
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.
🌐
Real Python
realpython.com › python-break
How to Exit Loops Early With the Python break Keyword – Real Python
February 25, 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.
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.
🌐
PythonHello
pythonhello.com › fundamentals › python-while-loops
While Loops
count = 0 while True: # infinite loop count += 1 if count > 10: break # exit loop when count > 10 print(count) print("Done!") ... The continue statement can be used to skip the remainder of the current iteration and move on to the next one.
🌐
Python.org
discuss.python.org › python help
How to write a loop with conditions - Python Help - Discussions on Python.org
January 11, 2022 - Hello, I have to write a loop that prompts a user for their age in a program that outputs an admission price for a cinema ticket (depending on the user’s age) I have just started writing basic loops like this one below,…
🌐
Tutorialspoint
tutorialspoint.com › python › python_loop_control.htm
Python Break, Continue and Pass Statements
The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop. The continue statement can be used in both while and for loops. for letter in 'Python': # First ...
🌐
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.
🌐
Altcademy
altcademy.com › blog › how-to-end-a-while-loop-in-python
How to end a while loop in Python
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 ...
🌐
W3Schools
w3schools.com › python › python_lists_loop.asp
Python - Loop Lists
Learn more about for loops in our Python For Loops Chapter. You can also loop through the list items by referring to their index number. Use the range() and len() functions to create a suitable iterable. Print all items by referring to their index number: thislist = ["apple", "banana", "cherry"] for i in range(len(thislist)): print(thislist[i]) Try it Yourself » · The iterable created in the example above is [0, 1, 2]. You can loop through the list items by using a while loop.
🌐
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): ...
🌐
W3Schools
w3schools.com › c › c_break_continue.php
C Break and Continue
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
Real Python
realpython.com › python-for-loop
Python for Loops: The Pythonic Way – Real Python
3 weeks ago - In this new loop implementation, you’re using a new list to store the result. Because of this, you don’t have to remove items anymore. You add the square values to the end of the new list using the .append() method. Python doesn’t allow you to add or remove items from a dictionary while ...
🌐
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.