You can use generators to simplify nested loops and make it easier to break out of them.
WolframAlpha helped me a lot when studying for Calculus...