- 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.
推薦閱讀
- 三菱FX3U/5U PLC從入門到精通
- 腦動力:C語言函數(shù)速查效率手冊
- 21天學(xué)通Java
- Moodle Course Design Best Practices
- 變頻器、軟啟動器及PLC實用技術(shù)260問
- 傳感器原理與工程應(yīng)用
- 軟測之魂
- MySQL Management and Administration with Navicat
- 微機組裝與維護教程
- Flash 8中文版全程自學(xué)手冊
- 巧學(xué)活用AutoCAD
- 數(shù)據(jù)庫技術(shù):Access 2003計算機網(wǎng)絡(luò)技術(shù)
- 深度學(xué)習(xí)實戰(zhàn)
- Building Impressive Presentations with Impress.js
- 機器學(xué)習(xí)公式詳解