summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-08-12 18:58:53 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-08-12 18:58:53 (GMT)
commit2f76f73d7326496b7fff114fd478e764c13111f4 (patch)
treeb1986cfab308eb9a8bd02c1792baca7b1df3c5e0 /Doc
parent614e44a0fa650751f7972bb7e38f00f5f7599871 (diff)
downloadcpython-2f76f73d7326496b7fff114fd478e764c13111f4.zip
cpython-2f76f73d7326496b7fff114fd478e764c13111f4.tar.gz
cpython-2f76f73d7326496b7fff114fd478e764c13111f4.tar.bz2
Issue #15630: Add an example for "continue" statement in the tutorial. Patch by
Daniel Ellis.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/tutorial/controlflow.rst19
1 files changed, 16 insertions, 3 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index 59b7fff..0616613 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -129,9 +129,6 @@ function, see :ref:`tut-loopidioms`.
The :keyword:`break` statement, like in C, breaks out of the smallest enclosing
:keyword:`for` or :keyword:`while` loop.
-The :keyword:`continue` statement, also borrowed from C, continues with the next
-iteration of the loop.
-
Loop statements may have an ``else`` clause; it is executed when the loop
terminates through exhaustion of the list (with :keyword:`for`) or when the
condition becomes false (with :keyword:`while`), but not when the loop is
@@ -166,6 +163,22 @@ when no exception occurs, and a loop's ``else`` clause runs when no ``break``
occurs. For more on the :keyword:`try` statement and exceptions, see
:ref:`tut-handling`.
+The :keyword:`continue` statement, also borrowed from C, continues with the next
+iteration of the loop::
+
+ >>> for num in range(2, 10):
+ ... if x % 2 == 0:
+ ... print("Found an even number", num)
+ ... continue
+ ... print("Found a number", num)
+ Found an even number 2
+ Found a number 3
+ Found an even number 4
+ Found a number 5
+ Found an even number 6
+ Found a number 7
+ Found an even number 8
+ Found a number 9
.. _tut-pass: