- 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.
推薦閱讀
- 機器學習實戰:基于Sophon平臺的機器學習理論與實踐
- 會聲會影X5視頻剪輯高手速成
- PostgreSQL 11 Server Side Programming Quick Start Guide
- UTM(統一威脅管理)技術概論
- Mastering Salesforce CRM Administration
- 自動化控制工程設計
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- OpenStack Cloud Computing Cookbook
- 智能生產線的重構方法
- 悟透AutoCAD 2009案例自學手冊
- Working with Linux:Quick Hacks for the Command Line
- AMK伺服控制系統原理及應用
- Puppet 3 Beginner’s Guide
- 傳感器原理及實用技術
- 工業機器人基礎