I am having trouble breaking out of multiple loops in my Python code and I am looking for some guidance from the community. I have a scenario where I need to perform nested looping and need to break out of all loops when a specific condition is met.
I have tried using the break
keyword with a label for the outer loop, but it only breaks out of the inner loop, and the outer loop continues execution. Here’s an example code snippet that demonstrates my problem:
for i in range(5):
for j in range(5):
if i*j > 6:
# I want to break out of all loops when i*j > 6
# But the following only breaks out of the inner loop
break
I am not sure how to proceed with this problem and would appreciate any suggestions or alternative methods to achieve the desired result.