I would like to understand why the following python code to find all prime numbers less than n works:
def prime(n):
    for q in range(2,n):
        for i in range(2,q):
            if q%i==0:
                print(q, "is not a prime")
                break
        else:
            print(q, "is a prime")
My problem is that I thought the else: should be aligned under the if: but it isn't in this code. I think the problem is that I do not understand well enough what the "break" does.
 
    