- 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.
推薦閱讀
- Hands-On Intelligent Agents with OpenAI Gym
- Mastering Proxmox(Third Edition)
- Getting Started with Clickteam Fusion
- VMware Performance and Capacity Management(Second Edition)
- AI 3.0
- 網絡綜合布線設計與施工技術
- Microsoft System Center Confi guration Manager
- 軟件工程及實踐
- 統計挖掘與機器學習:大數據預測建模和分析技術(原書第3版)
- 啊哈C!思考快你一步
- 基于ARM9的小型機器人制作
- Visual Basic項目開發案例精粹
- 精通ROS機器人編程(原書第2版)
- x86/x64體系探索及編程
- 巧學活用Linux