官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 英吉沙县| 镇江市| 富平县| 乡宁县| 美姑县| 长治县| 石泉县| 定边县| 泽库县| 偃师市| 广西| 平江县| 界首市| 姜堰市| 沙田区| 铅山县| 大厂| 外汇| 怀宁县| 邛崃市| 达尔| 双城市| 大悟县| 澄城县| 平昌县| 天台县| 湘乡市| 阿合奇县| 桦南县| 阜新市| 灵石县| 资阳市| 榆中县| 山西省| 怀来县| 稷山县| 瑞金市| 上栗县| 邵阳市| 桑植县| 军事|