Python循环-break和continue
break用于完全结束一个循环,跳出循环体,执行循环后面的语句
# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"
count = 0
while count <=10:
print('loop',count)
if count == 4:
break #结束整个循环
count +=1
print('End')
运行结果

continue用于终止本次循环,继续进行下一轮循环
for i in range(0,10):
if i == 3:
continue # 跳出本次循环,继续接下来的循环
print('loop', i)
print('End')
运行结果


浙公网安备 33010602011771号