Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python continue Statement

Python continue Statement

The Python continue statement jumps out of the current iteration, while break jumps out of the entire loop.

The continue statement tells Python to skip the remaining statements in the current iteration and then proceed to the next iteration.

The continue statement is used in while and for loops.

The syntax format of the continue statement in the Python language is as follows:


continue

Flow diagram:

Example:

Example (Python 2.0+)

#!/usr/bin/python

-- coding: UTF-8 --

for

letter

in

'

Python

'

:

First Example

if

letter

==

'

h

'

:

continue

print

'

Current letter :

'

,

letter

var

=

10

Second example

while

var

0

:

var

=

var

1

if

var

==

5

:

continue

print

'

Current variable value :

'

,

var

print

"

Good bye!

"

The example above produces:


当前字母 : P
当前字母 : y
当前字母 : t
当前字母 : o
当前字母 : n
当前变量值 : 9
当前变量值 : 8
当前变量值 : 7
当前变量值 : 6
当前变量值 : 4
当前变量值 : 3
当前变量值 : 2
当前变量值 : 1
当前变量值 : 0
Good bye!