当前位置:首页 > 云计算 > 正文内容

Python里有死循环吗

2022-05-04 03:08:40云计算1

何为死循环?在编程中,一个无法靠自身的控制终止的循环被称为死循环。

python中的死循环

这里True,代表1是真,0是假

i=0
whileTrue:
i=i+1
ifi==50:
print'Ihavegottotheround50th!'
continue
ifi>70:break
printi

死循环

i=0
whileTrue:
i=i+1
ifi==5000000:
print'Ihavegottotheround50th!'
break
#ifi>70:break
#printi

两种方法打印10000000

方法一

i=0
whilei<10000000:
i=i+1
continue
print'Ihavegottotheround',i
#break
#ifi>70:break
#print

方法二:

程序走完才走else,不然不走else

i=0
whilei<10000000:
i=i+1
#continue
else:
print'Ihavegottotheround',i
#break
#ifi>70:break
#printi

while和for循环对比(一个道理)

i=0
whilei<10000000:
i=i+1
#continue
else:
print'Ihavegottotheround',i
#break
#ifi>70:break
#printi
foriinrange(100):
printi
else:
print'Theloopisdone!'

python学习网,大量的免费python学习视频,欢迎在线学习!

本网站文章仅供交流学习 ,不作为商用, 版权归属原作者,部分文章推送时未能及时与原作者取得联系,若来源标注错误或侵犯到您的权益烦请告知,我们将立即删除.

本文链接:https://www.xibujisuan.cn/7406.html

标签: Python