What does the Python continue statement do? Detailed explanation of the usage of Python continue statement

Tomorin
Release: 2018-08-13 16:50:44
Original
6740 people have browsed it

This article mainly introduces python statements. The Python continue statement jumps out of this loop, and 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 to the next round of the loop. continue statement is used in while and for loops.

The Python language continue statement syntax format is as follows:

continue
Copy after login


Flow chart:

What does the Python continue statement do? Detailed explanation of the usage of Python continue statement

Example:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 for letter in 'Python':     # 第一个实例
   if letter == 'h':
      continue
   print '当前字母 :', letter
      
 var = 10             # 第二个实例
 while var > 0:              
   var = var -1
   if var == 5:
       continue
   print '当前变量值 :', var
       print "Good bye!"
Copy after login

Execution result of the above example:

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!

Knowledge points related to this article:

What is the role of the pass statement in the Python statement? A brief discussion on the usage of pass statement

#Where can the break statement be used? Daniel will tell you about the role of break in loop statements

I hope this article can help you in your work

The above is the detailed content of What does the Python continue statement do? Detailed explanation of the usage of Python continue statement. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!