Tags: #python #iterator
class Foo:
def __init__(self):
self.current = 0
self.limit = 5
def __iter__(self):
return self
def __next__(self):
if self.current >= self.limit:
raise StopIteration
else:
self.current += 1
return self.current - 1
for f in Foo():
print(f)