Examples of the use of continue statements in Python

Source: Internet
Author: User
The Python continue statement returns the start of a while loop. The continue statement rejects the rest of the statement execution in the current iteration of the loop and moves the control back to the top of the loop (the start position).

The continue statement can be used in while and for loops.
Grammar

The syntax for the Python continue statement is as follows:

Continue
Flow chart:

Example

#!/usr/bin/pythonfor "Python": # First   Example if letter  = = ' h ':   continue  print ' current Letter: ', Lettervar = ten          # 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 produced:

Current letter:pcurrent letter:ycurrent letter:tcurrent letter:ocurrent letter:ncurrent variable Value:9curren  T variable value:8current variable value:7current variable value:6current variable value:4current variable value: 3Current variable value:2current variable value:1current variable value:0good 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.