If what you're asking about is having an index while iterating over a collection, that's what enumerate is for.
Rather than do:
index = -1
for element in collection:
index += 1
print("{element} is the {n}th element of collection", element=element, n=index)
You can just write:
for index, element in enumerate(collection):
print("{element} is the {n}th element of collection", element=element, n=index)
edit
Responding to the original question, are you asking for something like this?
from itertools import count
def loop_year(year):
leap_year_count = 0
for year in count(year):
if (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0):
leap_year_count += 1
print("%s is a leap year") % (year)
if leap_year_count == 20:
break
loop_year(2020)
That said, I agree with ArtOfCode that a while-loop seems like the better tool for this particular job.
iin yourforloop?range(1,x = 21)supposed to do?