Search This Blog

155 Python Loops

 5) Loops

5.1 for loop
for i in [1,2,3]:
    print (i)

for loop with else, 
ints = [1, 2, 3, 4]

for d in [0,1,2,3]:
    if d == 3:
        break
else:
    print("No num left.")
print("1 num left")


5.2) while loop
m=5
i=0
while i < m:
    i=i+1
    print(i)


5.3 Nested loops
Nested loops is “one loop inside another loop”. 

No comments:

Post a Comment