- Python Programming with Raspberry Pi
- Sai Yamanoor Srihari Yamanoor
- 111字
- 2021-07-02 23:48:47
Breaking out of loops
Conditional statements can be used to break out of a loop execution (for loop and while loop). When a specific condition is met, an if statement can be used to break out of a loop:
i = 0
while True:
print("The value of i is ", i)
i += 1
if i > 100:
break
In the preceding example, the while loop is executed in an infinite loop. The value of i is incremented and printed on the screen. The program breaks out of the while loop when the value of i is greater than 100 and the value of i is printed from 1 to 100.
推薦閱讀
- 機(jī)器學(xué)習(xí)及應(yīng)用(在線實(shí)驗(yàn)+在線自測(cè))
- Verilog HDL數(shù)字系統(tǒng)設(shè)計(jì)入門與應(yīng)用實(shí)例
- 基于LabWindows/CVI的虛擬儀器設(shè)計(jì)與應(yīng)用
- UTM(統(tǒng)一威脅管理)技術(shù)概論
- SharePoint 2010開發(fā)最佳實(shí)踐
- Java Web整合開發(fā)全程指南
- 計(jì)算機(jī)網(wǎng)絡(luò)安全
- 完全掌握AutoCAD 2008中文版:機(jī)械篇
- 筆記本電腦維修90個(gè)精選實(shí)例
- 悟透AutoCAD 2009案例自學(xué)手冊(cè)
- 零起點(diǎn)學(xué)西門子S7-200 PLC
- Hands-On Data Warehousing with Azure Data Factory
- Mastering GitLab 12
- Hands-On Dashboard Development with QlikView
- 重估:人工智能與賦能社會(huì)