Apr 24, 2025
for variable in iterable:
variable: Counter or iterator, can be named anything (e.g., x, counter).iterable: Can be a range, string, etc.for x in range(1, 11):
print(x)
range(1, 11): Starts at 1, ends before 11, effectively counting to 10.reversed() function with range.for x in reversed(range(1, 11)):
print(x)
print("Happy New Year")
range().for x in range(1, 11, 2):
print(x)
credit_card = "1234-5678"
for x in credit_card:
print(x)
credit_card string, including dashes.continue and breakfor x in range(1, 21):
if x == 13:
continue
print(x)
for x in range(1, 21):
if x == 13:
break
print(x)