3 ms·
The "inside" part is slightly wrong, the payload is outside of the try/except clause: while True: try: number = next(iter_object)
by theamk 8y ago
The "inside" part is slightly wrong, the payload is outside of the try/except clause:
while True:
try:
number = next(iter_object)
except StopIteration:
break
sum += number
You can check this by throwing StopIteration inside the loop, and watching it propagate outside normally.