Loops
# While Loop
a = 1
while a < 5:
a += 1
print(a)
# For Loops execute a set number of times
for i in [0,1,2,3,4]:
print(i+6)
for i in range(5):
print(i+6)
# Nested Loops
for i in range(3):
for j in range(3):
print(i,j)
# Break loop control
for i in range(5):
if i == 2:
break
print(i)
for i in range(5):
if i == 2:
continue
print(i)
Last updated