From 0c0df28afa804d89a83ab62c2d562ab8315ab77d Mon Sep 17 00:00:00 2001 From: Gerard Weatherby Date: Fri, 6 Sep 2024 09:34:40 -0400 Subject: [PATCH 1/4] Draft --- Doc/tutorial/controlflow.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 677d7ca02c3f2f..a02a2ce99094df 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -166,15 +166,13 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo The :keyword:`break` statement breaks out of the innermost enclosing :keyword:`for` or :keyword:`while` loop. -A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!else` clause. +The :keyword:`!break` statement may be paired with an :keyword:`!else` clause. +If the loop exits without executing the break, the else clause executes. In a :keyword:`for` loop, the :keyword:`!else` clause is executed -after the loop reaches its final iteration. +after the loop reaches its final iteration if no break occurred. -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`. +In a :keyword:`while` loop, it's executed after the loop's condition becomes false if not break occurred. This is exemplified in the following :keyword:`!for` loop, which searches for prime numbers:: From cdbb517a64d3639043bce403acdeafddb30a8e9d Mon Sep 17 00:00:00 2001 From: Gerardwx Date: Fri, 6 Sep 2024 10:26:43 -0400 Subject: [PATCH 2/4] Rephrase to make each sentence true by itself. Emphasize the else must be paired with a break --- Doc/tutorial/controlflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index a02a2ce99094df..4c8a6d61e1c7af 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -172,7 +172,7 @@ If the loop exits without executing the break, the else clause executes. In a :keyword:`for` loop, the :keyword:`!else` clause is executed after the loop reaches its final iteration if no break occurred. -In a :keyword:`while` loop, it's executed after the loop's condition becomes false if not break occurred. +In a :keyword:`while` loop, it's executed after the loop's condition becomes false if no break occurred. This is exemplified in the following :keyword:`!for` loop, which searches for prime numbers:: From d139a225076daa2b725ea39260f6d1022b498b7e Mon Sep 17 00:00:00 2001 From: Gerardwx Date: Fri, 6 Sep 2024 10:42:51 -0400 Subject: [PATCH 3/4] Remove trailing whitespace --- Doc/tutorial/controlflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 4c8a6d61e1c7af..0b8f971185f224 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -166,7 +166,7 @@ arguments. In chapter :ref:`tut-structures`, we will discuss in more detail abo The :keyword:`break` statement breaks out of the innermost enclosing :keyword:`for` or :keyword:`while` loop. -The :keyword:`!break` statement may be paired with an :keyword:`!else` clause. +The :keyword:`!break` statement may be paired with an :keyword:`!else` clause. If the loop exits without executing the break, the else clause executes. In a :keyword:`for` loop, the :keyword:`!else` clause is executed From 9538941fae73d5ffe88b341fa2d4eb033b37763b Mon Sep 17 00:00:00 2001 From: Gerardwx Date: Fri, 6 Sep 2024 10:47:14 -0400 Subject: [PATCH 4/4] Issue #123786