程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Illustration of Python | break statement

編輯:Python
ShowMeAI research center

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

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 :

break Statement execution flow

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 !

Data and code download

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 :

  • Python Quick reference table

Expand references

  • Python course —Python3 file
  • Python course - Liao Xuefeng's official website

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved