A brief analysis of break continue exit () pass in Python

Source: Internet
Author: User

1. Break

Break is to terminate this cycle, such as you many while loop, you write a break in one of the while loop, satisfies the condition, only terminates this while inside the loop, the program jumps to the upper layer while loops continues to go down

Example with a simple for loop

For I in range (10):
Print ("-----%d-----"%i)
For j in Range (10):
If J > 5:
Break
Print (j)
When we meet j>5, the second layer of for does not loop, continue to jump to the previous layer of the loop

2, continue
Continue is the time to loop to this point, to perform some of the operations continue here, after the execution, continue to loop to meet the conditions of this layer of the loop need to do, do not terminate this layer of loop
The above example makes a change
For I in range (10):
Print ("-----%d-----"%i)
For j in Range (10):
If J > 5 and J <= 8:
Print ("I am continue special")
Continue
Print (j)
The loop here will print out what J needs to do between 5-8, but will not terminate the second loop, do not satisfy the number between 5-8, and then loop on the following things to do

3, exit () exit the whole program, very good understanding
4, pass is just a placeholder, what do not do

A brief analysis of break continue exit () pass in Python

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.