- 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.
推薦閱讀
- Circos Data Visualization How-to
- Hadoop 2.x Administration Cookbook
- 圖解PLC控制系統梯形圖和語句表
- 來吧!帶你玩轉Excel VBA
- 機器學習與大數據技術
- VMware Performance and Capacity Management(Second Edition)
- AutoCAD 2012中文版繪圖設計高手速成
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- Moodle Course Design Best Practices
- Storm應用實踐:實時事務處理之策略
- 多媒體制作與應用
- 電腦日常使用與維護322問
- Photoshop行業應用基礎
- PyTorch深度學習
- Getting Started with Tableau 2019.2