while 条件:
代码块
i = 1
while i <= 5:
print(i)
i += 1
输出:
1
2
3
4
5
while 条件:
代码块
else:
代码块
i = 6
while i <= 5:
print(i)
i += 1
else:
print("条件为假")
输出:
条件为假
break
i = 1
while True:
print(i)
i += 1
if i > 5:
break
输出:
1
2
3
4
5
continue
i = 1
while i <= 5:
if i == 3:
continue
print(i)
i += 1
输出:
1
2
4
5