You'll need to break out of each loop separately, as people have mentioned in the comments for your question, break only stops the loop which it's in

for x in userpassword[k]:
    for z in lowercaselist:
        if x in z:
            newpasswordlist.append(z)
            k +=1
            break
    if x in z: # added an extra condition to exit the main loop
        break

You'll need to do this for both loops. If you want to break out of the while loop as well, then you can add if x in z: break in that loop as well.

Answer from Tom Fuller on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_keyword_break.asp
Python break Keyword
Python Examples Python Compiler ... Python Interview Q&A Python Bootcamp Python Training ... The break keyword is used to break out a for loop, or a while loop....
🌐
Reddit
reddit.com › r/learnpython › use of break in python
r/learnpython on Reddit: Use of break in Python
May 11, 2019 -

Quite a number of my fellow teachers have been saying that we should NEVER use breaks in loops. However in our examination there is often a need to validate an input e.g.

while True:
    ID = input("What is the cow's ID code?")
    if len(ID) == 3:
        CowID.append(ID)
        break
    else:
        print("Cow ID has been entered wrongly.")

The break works perfectly well in Python, but it has been suggested to me that I avoid using such constructs. What are your thoughts on this and does anyone have credible sources one way or another? In the age of the Internet my students will quickly find break and I would need a very strong argument as to why they don't use it. Equally, if I go against these other teachers I will need credible evidence as to why I am doing it this way.

Your thoughts, arguments and ideas are very much appreciated. This debate has been rumbling on already for over a month and I would like to get a good answer before I plan next year's lessons.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-break-statement
Python Break Statement - GeeksforGeeks
The break statement in Python is used to immediately terminate a for or while loop when a specified condition is met.
Published   June 5, 2026
🌐
Mimo
mimo.org › glossary › python › break-statement
Python Break Statement: Syntax, Usage, and Practical Examples
When using a for loop, the break statement halts the iteration as soon as the condition is met. ... colors = ["red", "green", "blue", "stop", "yellow"] for color in colors: if color == "stop": break print(color) ... This shows a classic example of using python break for loop control to prevent ...
🌐
Coursera
coursera.org › tutorials › python-break
How to Use Python Break | Coursera
In Python, break allows you to exit a loop when an external condition is met. Normal program execution resumes at the next statement. You can use a break statement with both for loops and while loops.
🌐
Programiz
programiz.com › python-programming › break-continue
Python break and continue (With Examples)
We can use the break statement with the for loop to terminate the loop when a certain condition is met.
Find elsewhere
🌐
Saurus
saurus.ai › home › the python break statement
Python Break Statement Clearly Explained
October 8, 2024 - The Python break statement allows you to prematurely exit a loop before its natural completion. This statement is handy when you want to stop a loop’s execution for a condition that is not convenient to check under the loop’s normal syntax.
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.6 documentation
We have seen that the for statement ... we will discuss list() in more detail. The break statement breaks out of the innermost enclosing for or while loop:...
🌐
Python documentation
docs.python.org › 3 › reference › index.html
The Python Language Reference — Python 3.14.6 documentation
7.8. The raise statement · 7.9. The break statement · 7.10. The continue statement · 7.11. The import statement · 7.12. The global statement · 7.13. The nonlocal statement · 7.14. The type statement · 8. Compound statements · 8.1. The if statement · 8.2. The while statement ·
🌐
Flexiple
flexiple.com › python › python-break-continue
How to use Python Break & Continue statements? - Flexiple
March 11, 2022 - Practicing them using a while true loop would help you get a better understanding of how the flow can be changed. However, remember to insert a break before running it or you would create an infinity loop. Once you have properly understood this you can have a look at the Python pass statement which is another loop control statement.
🌐
HowToDoInJava
howtodoinjava.com › home › python flow control › python break statement
Python break Statement Example
October 1, 2022 - Python break statement is used to terminate the a loop which contains the break statement. When a break statement is executed inside a loop, the program execution jumps to immidiately next statement after the loop.
🌐
Python.org
discuss.python.org › ideas
Break from multiple loops at once - Ideas - Discussions on Python.org
September 15, 2025 - Often, I want to use break to break not only out of the innermost loop, but also out of further loops. It’s a lot more inconvenient to have to set a looping boolean before the outer loop, set it to False in the if clause…
🌐
Tutorial Gateway
tutorialgateway.org › python-break
Python break Statement
June 11, 2026 - The Python break statement is an important one used to alter the flow of a loop structure by terminating the current loop. The break statement is beneficial for exiting control from for loops, while loops, and nested Loops.
🌐
Unstop
unstop.com › home › blog › python break statement & uses explained (with code examples)
Python Break Statement & Uses Explained (With Code Examples)
November 28, 2024 - Python break statement causes a loop to terminate immediately. It is often use to exit loops prematurely, optimize code, in try-except blocks and more.
🌐
ProjectPro
projectpro.io › recipes › use-continue-and-break-statement-within-loop-in-python
How to Use Break and Continue Statements in Python? -
March 8, 2024 - Get Your Hands-on Python Projects with ProjectPro! The break statement in Python is used to exit a loop prematurely. When encountered, it immediately terminates the innermost loop, regardless of the loop condition.
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
Python · for i in range(1, 5): for j in range(i): print(i, end=' ') print() Output · 1 2 2 3 3 3 4 4 4 4 · Explanation: Outer loop for i in range(1, 5) controls the number of rows and Inner loop for j in range(i) runs i times for each row. print(i, end=' ') prints the value of i on the same line and print() moves output to the next line after each row. For loop vs while loop · Eliminating Loop · Control statements ·
Published   June 11, 2026
🌐
Quora
quora.com › In-Python-why-does-the-break-statement-work-inside-of-a-while-loop-but-not-an-if-statement
In Python, why does the 'break' statement work inside of a while loop but not an if statement? - Quora
Answer (1 of 2): A loop basically uses a jump to go back to the beginning of its code block. Some inherently mutate variables along the while while others leave that part to be done in the aforementioned code block itself. Consider how else you could terminate the loop similar to the break keywor...
🌐
freeCodeCamp
freecodecamp.org › news › python-break-statement-tutorial
Python Break Statement – How to Break Out of a For Loop in Python
April 16, 2024 - From the above examples, you learned how to use the break statement to terminate for and while loops in Python.