Full parsing of break, continue, exit () and pass in python, and full parsing in python

Source: Internet
Author: User

Full parsing of break, continue, exit () and pass in python, and full parsing in python

1. break

Break terminates this loop. For example, if you write a break in one of the while loops that meet the condition, only the loop in the while loop is terminated, the program will jump to the previous layer while the loop continues to go down

Take a simple for loop as an Example

For I in range (10): print ("----- % d -----" % I) for j in range (10): if j> 5: break print (j)

When j> 5 is encountered, the for on the second layer will not be cyclic, And the next layer will continue to be cyclic.

2. continue

When the continue is directed to this point, execute some operations in the continue. After the execution is complete, continue the loop that meets the conditions, and do not terminate the loop.

The above example is modified.

For I in range (10): print ("----- % d -----" % I) for j in range (10): if j> 5 and j <= 8: print ("I am a special continue") continue print (j)

Here, the loop will print out the things that j needs to do between 5 and 8, but it will not terminate the second-layer loop. If it does not meet the number between 5 and 8, it will then loop the things that need to be done below.

3. exit ()Exit the entire program.

4. passIt's just a placeholder and does nothing.

The full analysis of break, continue, exit (), and pass in python above is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.

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.