python学习之while语句

while循环

1.简单的while循环
while True:
print("")
#这是一个简单的while循环,当等于True时会一直打印1 2.while执行多少次后退出
coun=0
while True:
print(coun)
coun+=1
if coun == 10:
print("not while,exit...")
break
#循环10次后退出
运行结果:

0
1
2
3
4
5
6
7
8
9
not while,exit...

3.循环跳过中间某段

coun=0
while True:
coun+=1
if coun >= 4 and coun <= 8:
continue
print(coun)
if coun == 10:
print("not while,exit...")
break
#打印10个数跳过4和8中间的数
运行结果:

1
2
3
9
10
not while,exit...

上一篇:Secret 的使用场景 - 每天5分钟玩转 Docker 容器技术(109)


下一篇:MySQL5.6的4个自带库详解