Python continue statement usage instance

  • 2020-04-02 13:32:54
  • OfStack

Python USES the continue statement to break out of the loop, while break breaks out of the entire loop. The continue statement is used to tell Python to skip the rest of the current loop and proceed with the next loop. The continue statement is used in the while and for loops.

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

continue

Ii. Logical flow chart
< img border = 0 id = theimg onclick = window. The open this. (SRC) SRC = "/ / files.jb51.net/file_images/article/201403/2014311174151636.jpg? 2014211174346 ">

Iii. Examples:

#!/usr/bin/python
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!"

Execution results of the above examples:

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!


Related articles: