ReferenceException types
StopIteration
An iterator has nothing left. for loops catch this for you.
Signature
StopIterationReturns
Raised by next() at the end.
Example
Python
it = iter([1])
print(next(it))
try:
next(it)
except StopIteration:
print("nothing left")
print(next(iter([]), "default instead"))Output
1 nothing left default instead