[docs] [issue31156] Stopiteration terminates while-loop

Günter Rote report at bugs.python.org
Wed Aug 9 05:49:19 EDT 2017


New submission from Günter Rote:

It should be mentioned in the documentation that 

A StopIteration exception raised in the body of a while loop will terminate (and is caught by) the while-loop, thus leading to graceful termination.

A good place would be here:
1) https://docs.python.org/3/reference/compound_stmts.html#the-while-statement

I don't know how such a StopIteration termination of a while loop
affects the else-clause. This should be clarified.

Here:
2) https://docs.python.org/3/library/exceptions.html#StopIteration
it would be good to explicitly state:

An enclosing while-loop or for-loop acts like an implicit catch for StopIteration. The StopIteration exception will terminate the loop.

(I guess, a for-loop is also just terminated when the StopIteration originates in the BODY of the loop, although this is not the typical case.)

----------
assignee: docs at python
components: Documentation
messages: 299982
nosy: Günter Rote, docs at python
priority: normal
severity: normal
status: open
title: Stopiteration terminates while-loop
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31156>
_______________________________________


More information about the docs mailing list