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