Python continue statement

Source: Internet
Author: User

Python continue statement
Python continue statement

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

The continue statement is used to tell Python to skip the remaining statement of the current loop and then continue 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

Flowchart:

Instance:

#! /Usr/bin/python #-*-coding: UTF-8-*-for letter in 'python': # first instance if letter = 'H ': continue print 'current letter: ', lettervar = 10 # The Second Instance while var> 0: var = var-1 if var = 5: continue print 'current variable value :', varprint "Good bye! "

Execution result of the above instance:

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.
Python pass statement 

Python pass is a null statement to maintain the integrity of the program structure.

Passass does not do anything. It is generally used as a placeholder statement.

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

pass

Instance:

#! /Usr/bin/python #-*-coding: UTF-8-*-# output each letter of Python in 'python': if letter = 'H ': pass print 'this is the pass block 'print 'current letter:', letterprint "Good bye! "

Execution result of the above instance:

Current letter: P current letter: y current letter: t this is the pass block current letter: h current letter: o current letter: nGood bye!
!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.