Unbound or infinite iterator
Of course the user will have to be carefull not to try to flatten the iterator, not to try to get all the values from it, as that will only create an infinite loop or a never ending operation.
In this very simple example we count from 0 and we never stop.
When we use the Counter in the for loop we need to include a stop-condition, otherwise our loop will never end.
class Counter(): def __init__(self): self.count = 0 def __iter__(self): return self def __next__(self): self.count += 1 return self.count for c in Counter(): print(c) if c > 10: break
1 2 3 4 5 6 7 8 9 10 11