Apprendre Python - UPDATE 1.5-continue: continue vs. else

This commit is contained in:
Fred Z 2017-12-27 01:13:27 +01:00
parent ad4fac76ee
commit 2acd31a8de

View File

@ -6,7 +6,7 @@
# OpenClassrooms - Apprenez à programmer en Python - Les boucles # OpenClassrooms - Apprenez à programmer en Python - Les boucles
# https://openclassroom # https://openclassroom
print("Fonctonnement a reproduire:") print(" Fonctionnement a reproduire:")
i = 1 i = 1
while i < 20: while i < 20:
if i % 3 == 0: if i % 3 == 0:
@ -14,10 +14,9 @@ while i < 20:
print("On incremente i de 4. i =", i) print("On incremente i de 4. i =", i)
continue continue
print("La variable i =", i) print("La variable i =", i)
i += 1 # Dans le cas classique on ajoute juste 1 à i i += 1
i = 0
print("boucle «for», probleme de scope avec la valeur de i") print(" boucle «for», probleme de scope avec la valeur de i")
for i in range(1,20): for i in range(1,20):
if i % 3 == 0: if i % 3 == 0:
i += 4 i += 4
@ -26,3 +25,12 @@ for i in range(1,20):
print("La variable i =", i) print("La variable i =", i)
i += 1 i += 1
print(" Remplacement du «contine» par un «else»:")
i = 1
while i < 20:
if i % 3 == 0:
i += 4
print("On incremente i de 4. i =", i)
else:
print("La variable i =", i)
i += 1