mardi 2 juin 2020

here, for a non prime number, the break statement in the inner loop is executed but the else statement of the outer loop is not executed, why?

L = []
nmax = 30

for n in range(2, nmax):
    for factor in L:
        if n % factor == 0:
            break
    else: # no break
        L.append(n)
print(L)

Does the else in the outer loop work if the if statement is not execute din the inner loop...are they really connected inspite being in different loops

Aucun commentaire:

Enregistrer un commentaire