Python Break and continue

Source: Internet
Author: User

 forMinchRange (3):    ifm = =0: forNinchRange (3):            ifn = = 1:                Print(m,n)Continue                Print(n)ifn = = 1:                Print(M,n)
if n = = 2:
Print (M,n)
ifm = = 1: forXinchRange (3): ifx = = 1: Print(m,x) Break Print(n)ifx = = 2: Print(m,x)Else: Print(m,n,x) D:\untitled\venv\Scripts\python.exe D:/untitled/bogls/jia2.py01
0 21 11) 2 1Process finished with exit code 0

Recognize the interruption in Python, first look at two sentences, break: Jump out of the entire for loop, continue: jump out of this cycle (continue rarely used). The Python code is executed from top to bottom, and the loop executes repeatedly until the loop ends or is interrupted.

Then analyze the code above

When ' m==0 ' enters ' for N in range (3) ' Loop, when ' n==0 ' is not satisfied with three conditions in the IF statement in the loop, the loop continues ' n==1 ' satisfies the condition execution if statement output ' 0,1 ', then executes continue out of the loop (without executing the next output statement ' Print (n) ' at the same time jumping out of the ' n==1 ' loop, not judging the following two if statements), entering the ' n==2 ' loop, judging three if statements, and a third output (m,n).

When ' m==1 ' enters the ' for X in range (3) ' Loop, when ' x==1 ' satisfies the first if statement, the output (m,n), and then executes break, jumps out of the entire ' for X in range (3) ' Loop. Now there is only one total loop executing the ' for M in range (3) ', the total loop ends the Else statement.

Python Break and continue

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.