python中的死循环在弄呀?

python中的死循环在弄呀?,第1张

python中型芹的死循环

这里True,代表1是穗念真,猜租困0是假

i = 0

while True:

i = i + 1

if i == 50:

print 'I have got to the round 50th!'

continue

if i>70:break

print i

死循环

i = 0

while True:

i = i + 1

if i == 5000000:

print 'I have got to the round 50th!'

break

# if i>70:break

# print i

正确,Python中的循环控制语句有以下三种:

break语句:用于跳出循环语句,即在满足特定条件时强制中断循环,然后执行循环体后面的基洞语句。

示例:

Copy code

for i in range(5):

if i == 3:

break

print(i)

输出结果

Copy code

0

1

2

continue语句:用于跳过当前循环的执行,即在满足特定条件时跳过当前循环中剩余的语句,直接进行下一轮循环 *** 作。

示例:

Copy code

for i in range(5):

if i == 3:

continue

print(i)

输出结果:

Copy code

0

1

2

4

pass语句:用于表示占位符,即在不需要执行任何语句的地方使用,保证程序搏渗枯的结构完整性。

示喊腊例:

Copy code

for i in range(5):

if i == 3:

pass

print(i)

输出结果:

Copy code

0

1

2

3

4

如果要写成死循旁塌环,那差启袭么就不要写退出语句break。虚兄

如:

while True:

#程序语句

如果在程序语句中没有退出语句,那么该段段就会变成死循环。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12344554.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存