python loop break, continue, exit (), the difference between the pass

1, break: out of the loop, no longer perform

For use in the while loop and
to terminate the loop statements, i.e., no loop condition or False Condition recursive sequence has not been fully completed, will stop the execution loop
if a nested loop, break statement stops execution of the innermost loop, and start the next line of code

Here Insert Picture Description

2, continue: out of this cycle, the next execution time

For use in the while loop and
to skip the remaining statements in the current cycle, and then continue to the next cycle of
the cycle time to this point, perform certain operations continue here, after the expiry performed, this continues to meet the conditions layer cycle needs to be done, this layer does not terminate the cycle (just out of this one).

continue statement to jump out of this cycle, and break out of the cycle.

Here Insert Picture Description

3, exit (): End / Quit the entire program

for element in "Python":  
     if element == "t":  
         exit()  
     else:
     	print(element) 
#输出:Py

4, pass: can be understood as "program by" do nothing, only play the role of placeholder

for element in "Python":  
	if element == "y":  
		pass  
	else:  
		print(element)
#输出:Pthon

Learning to finish: Python in the break, continue, exit (), pass terminate difference cycle

Published 43 original articles · won praise 10 · views 4871

Guess you like

Origin blog.csdn.net/yeyuanxiaoxin/article/details/104887199