文章目录
一、While循环:
1.While基本结构
while True:
print('循环体')
2.终止循环
2.1 改变条件
A = 1
while A == 1:
print('1')
A = 2
print('2')
2.2 break(直接退出循环)
A = 1
while A == 1:
print('1')
break
print('2')
2.3 continue(退出本次循环)
A = 2
while A == 1:
print('1')
continue
print('2')
3.While else :
【如果遇见break则跳过else】
3.1 无break
A = 0
while A < 5:
A += 1
print(A)
else:
print('进入else')
3.2 加break
A = 0
while A < 5:
A += 1
print(A)
break
else:
print('进入else')