Python continue statement
Python continue statement jumps out of this loop, while break jumps out of the entire loop.
The continue statement is used to tell Python to skip the remaining statements of the current loop and then continue with the next round of loops.
The continue statement is used in while and for loops.
The Python language continue statement syntax format is as follows:
continue
Flow chart:
Example:
!/usr/bin/python
# -*- coding: UTF-8 -*-
for letter in 'Python': #First instance
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!"
# -*- coding: UTF-8 -*-
for letter in 'Python': #First instance
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!"
Current letter: P
Current letter: y
Current letter: t
Current letter: o
Current letter: n
Current variable value: 9
Current variable value: 8
Current variable value: 7
Current variable value: 6
Current variable value: 4
Current variable value: 3
Current variable value: 2
Current variable value: 1
Current variable value: 0
Good bye!
Current letter: t
Current letter: o
Current letter: n
Current variable value: 9
Current variable value: 8
Current variable value: 7
Current variable value: 6
Current variable value: 4
Current variable value: 3
Current variable value: 2
Current variable value: 1
Current variable value: 0
Good bye!