How can I break out of nested loops in Python cleanly?

Using a return in a Function: I’ve often found that if the nested loops are inside a function, using return can be a clean way to exit both loops at once. Here’s an example:

def break_nested():
    for x in range(10):
        for y in range(10):
            print(x * y)
            if x * y > 50:
                return
break_nested()

This ensures that as soon as the condition is met, the loops are exited immediately. I like this approach because it keeps the logic concise while achieving the same effect.