author : Han Xinzi @ShowMeAI
Tutorial address :http://www.showmeai.tech/tutorials/56
This paper addresses :http://www.showmeai.tech/article-detail/73
Statement : copyright , For reprint, please contact the platform and the author and indicate the source
Python break sentence , Breaking the smallest closed for or while loop .
break Statement to terminate a loop statement , That is, there is no cycle condition False The condition or sequence is not completely recursive , It also stops executing loop statements .
In a nested loop ,break Statement will stop executing the deepest loop , And start executing the next line of code .
Python Language break Sentence syntax :
break
flow chart :
Here's a code example ( The code can be in On-line python3 Environmental Science Run in ):
for letter in 'ItIsShowMeAI': # First instance if letter == 'h': break print(' The current letter :', letter) var = 10 # Second example while var > 0: print(' Current variable value :', var) var = var -1 if var == 5: # When variables var be equal to 5 To exit the loop break print(" complete !")
The execution result of the above example :
The current letter : I The current letter : t The current letter : I The current letter : s The current letter : S Current variable value : 10 Current variable value : 9 Current variable value : 8 Current variable value : 7 Current variable value : 6 complete !
The code for this tutorial series can be found in ShowMeAI Corresponding github Download , Can be local python Environment is running , Babies who can visit foreign websites can also directly use google colab One click operation and interactive operation learning Oh !
This tutorial series covers Python The quick look-up table can be downloaded and obtained at the following address :