This article records the more interesting things, but also more important. Let's take a look at the break statement first. The Python break statement, like in the C language, breaks the minimum enclosing for or while loop. The break statement terminates the Loop statement, that is, the loop condition does not have a false condition, or the sequence is not fully recursive, and the loop statement is stopped. The break statement is used in the while and for loops. If we use a nested loop, the break statement stops executing the deepest loop and starts executing the next line of code. Look at the syntax:
Break
Here is the flowchart of it:
Here, let's take a look at the example:
#!/usr/bin/python#-*-Coding:utf-8-*- For Letter Inch ‘Python‘:# The first instance of If Letter==‘H‘:Break Print ‘Current Letter:‘,Letter Var=10 # a second instanceWhile Var>0:Print ‘Current variable Value:‘var var = var -1 if var = = Span class= "Hl-number" >5: # when variable var equals 5 o'clock Exit loop Span class= "hl-reserved" > break print "good bye!
The result of the above instance execution:
Current Letter :PCurrent Letter :Y current letter : T current variable value : 10 Current variable value : 9 current variable value : 8 current variable value : 7 current variable value : 6good Bye!
OK, let's take a look at the continue statement. The Python continue statement jumps out of the loop, and break jumps out of the loop. is a delete effect that exists in order to remove certain unwanted components that meet the loop condition. The continue statement is used to tell Python to skip the remaining statements of the current loop, and then proceed to the next round of loops. The continue statement is used in the while and for loops. Look at the syntax format:
Continue
Here is the flowchart of it:
Here, let's see the example:
#!/usr/bin/python#-*-Coding:utf-8-*- For Letter Inch ‘Python‘:# The first instance ofIf Letter==‘H‘:Continue Print ‘Current Letter:‘,Letter Var=10 # a second instanceWhile Var>0:Var=Var-1 if var = = Span class= "Hl-number" >5: continue print current variable value: ' var< Span class= "Hl-code" >print "good bye!
The result of the above instance execution:
Current Letter :PCurrent Letter :YCurrent Letter :TCurrent Letter :OCurrent Letter :NCurrent variable Value : 9Current variable Value : 8Current variable Value : 7Current variable Value : 6 current variable value : 4 Current variable value : 3 current variable value : 2 current variable value : 1 current variable value : 0good Bye!
Come here, let's have a look at the last pass empty statement. The Python Pass is an empty statement in order to maintain the integrity of the program structure. Pass does not do anything, generally used as a placeholder statement. Look at the syntax format:
Pass
Let's take a look at the example:
#!/usr/bin/python#-*-coding:utf-8-*-# output Python for each letter for letter in ' Python ' : if letter Span class= "pun" >== ' h ' : print ' This is pass block ' Span class= "KWD" >print ' current letter: ' , letter< Span class= "KWD" >print "good bye!"
The result of the above instance execution:
current letter :< Span class= "PLN" > P current letter : y current letter : T this is pass block current letter : H current letter : O current letter : Ngood Bye!
OK, here, the content is finished, if it feels good, please more praise support oh ...
python2.7 Getting Started---Break statement &continue statement &pass empty statement