summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-23 09:11:35 (GMT)
committerGitHub <noreply@github.com>2023-07-23 09:11:35 (GMT)
commit7d414873b3a020cec318d53cc1bb62ccdac061bd (patch)
treeae06105436da83dcf6d67f626ef82bed747207e1 /Doc/tutorial
parent9875b177a9ef6d062eee65a501621743e443f82e (diff)
downloadcpython-7d414873b3a020cec318d53cc1bb62ccdac061bd.zip
cpython-7d414873b3a020cec318d53cc1bb62ccdac061bd.tar.gz
cpython-7d414873b3a020cec318d53cc1bb62ccdac061bd.tar.bz2
[3.11] gh-107017: removed mention that C does it the same way (GH-107020) (#107098)
Co-authored-by: Jakub Červinka <cervinka.jakub.1989@gmail.com>
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/controlflow.rst23
1 files changed, 15 insertions, 8 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index e140f51..138d87f 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -4,8 +4,8 @@
More Control Flow Tools
***********************
-Besides the :keyword:`while` statement just introduced, Python uses the usual
-flow control statements known from other languages, with some twists.
+As well as the :keyword:`while` statement just introduced, Python uses a few more
+that we will encounter in this chapter.
.. _tut-if:
@@ -163,14 +163,21 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo
:keyword:`!break` and :keyword:`!continue` Statements, and :keyword:`!else` Clauses on Loops
============================================================================================
-The :keyword:`break` statement, like in C, breaks out of the innermost enclosing
+The :keyword:`break` statement breaks out of the innermost enclosing
:keyword:`for` or :keyword:`while` loop.
-Loop statements may have an :keyword:`!else` clause; it is executed when the loop
-terminates through exhaustion of the iterable (with :keyword:`for`) or when the
-condition becomes false (with :keyword:`while`), but not when the loop is
-terminated by a :keyword:`break` statement. This is exemplified by the
-following loop, which searches for prime numbers::
+A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!else` clause.
+
+In a :keyword:`for` loop, the :keyword:`!else` clause is executed
+after the loop reaches its final iteration.
+
+In a :keyword:`while` loop, it's executed after the loop's condition becomes false.
+
+In either kind of loop, the :keyword:`!else` clause is **not** executed
+if the loop was terminated by a :keyword:`break`.
+
+This is exemplified in the following :keyword:`!for` loop,
+which searches for prime numbers::
>>> for n in range(2, 10):
... for x in range(2, n):