For loops in Python are easy πŸ”
Bro Code Bro Code
1.84M subscribers
225,653 views
0

 Published On Oct 23, 2022

#python #course #tutorial

00:00:00 iterate forwards
00:01:39 iterate backwards
00:02:15 step
00:02:44 iterate over a string
00:03:26 continue
00:04:19 break
00:04:35 conclusion

for loops = execute a block of code a fixed number of times.
You can iterate over a range, string, sequence, etc.

--------------- EXAMPLE 1 ---------------

for x in range(1, 11):
print(x)

--------------- EXAMPLE 2 ---------------

for x in reversed(range(1, 11)):
print(x)

print("Happy New Year!")

--------------- EXAMPLE 3 ---------------

for x in range(1, 11, 2):
print(x)

--------------- EXAMPLE 4 ---------------

credit_card = "1234-5678-9012-3456"

for x in credit_card:
print(x)

--------------- CONTINUE ---------------

for x in range(1, 21):
if x == 13:
continue
else:
print(x)

--------------- BREAK ---------------

for x in range(1, 21):
if x == 13:
break
else:
print(x)

show more

Share/Embed