while循环

1.简单的while循环
while
True: print("1")
#这是一个简单的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...

 

相关文章:

  • 2021-04-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-12-22
  • 2021-06-22
  • 2021-05-03
猜你喜欢
  • 2021-07-29
  • 2021-12-06
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案