Examples of using the Continue statement in Python

Source: Internet
Author: User
This article describes how to use the Continue statement in Python. it is the basic knowledge in getting started with Python. if you need it, you can refer to the Python continue statement to return the start of the while loop. The Continue statement rejects the execution of other statements in the current iteration of the loop and moves the control to the top of the loop (start position ).

The continue statement can be used in a while or for loop.
Syntax

The syntax of the Python continue statement is as follows:

Continue
Flowchart:

Example

#! /Usr/bin/pythonfor letter in 'Python': # First Example if letter = 'h': continue print 'current Letter :', lettervar = 10 # Second Examplewhile var> 0: var = var-1 if var = 5: continue print 'current variable value: ', varprint "Good bye! "

When the above code is executed, the following results are generated:

Current Letter: PCurrent Letter: yCurrent Letter: tCurrent Letter: oCurrent Letter: nCurrent 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!

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.