mercredi 11 août 2021

if else elif in "for" python3

I have code:

j=1 while j<10: for i in range(10): print(i) if i!=3: j+=1 print('j',j) elif i==5: break

print('j before cont',j)
continue

I expect that when the variable 'i' reaches the value 5, the cycle will be interrupted and the count of 'i' will start again, and the count of 'j' will continue. But the 'for' loop does not stop even when 'i' reaches 5. Please tell me why this is happening. The result of the code:

0 j 2 1 j 3 2 j 4 3 4 j 5 5 j 6 6 j 7 7 j 8 8 j 9 9 j 10 j before cont 10

Aucun commentaire:

Enregistrer un commentaire