python的while循环返回_python中如果在while循环中是return会导致循环中断

python中如果在while循环中是return会导致循环中断

[root@10.144.5.223 root]# cat test_while_return.py

count = 0

while (count < 6):

print ‘The count is:‘, count

count = count + 1

print "Good bye!"

print ‘-‘*20

while (count >= 3):

print ‘The count is:‘, count

count -= 1

print "Good bye!"

print ‘-‘*20

while (count != 0):

print ‘The count is:‘, count

count -= 1

print "Good bye!"

print ‘#‘*20

def checkstatus():

Checktimes = 3

Mysql_ok = 1

while (Checktimes != 0):

Checktimes -= 1

if Mysql_ok == 1:

print (‘Mysql_ok‘,Mysql_ok)

return True

#exit( 0 )

else:

print (‘Mysql_ok‘,dbip,Mysql_ok)

return False

#exit( 1 )

checkstatus()

print ‘*‘*20

def checkstatus():

Checktimes = 3

Mysql_ok = True

while (Checktimes != 0):

Checktimes -= 1

if Mysql_ok == 1:

print (‘Mysql_ok‘,Mysql_ok)

mysqlcheck=True

#exit( 0 )

else:

print (‘Mysql_ok‘,dbip,Mysql_ok)

mysqlcheck=False

#exit( 1 )

return mysqlcheck

checkstatus()

print ‘+‘*20

print checkstatus()

[root@10.144.5.223 root]#

[root@10.144.5.223 root]# python test_while_return.py

The count is: 0

The count is: 1

The count is: 2

The count is: 3

The count is: 4

The count is: 5

Good bye!

--------------------

The count is: 6

The count is: 5

The count is: 4

The count is: 3

Good bye!

--------------------

The count is: 2

The count is: 1

Good bye!

####################

(‘Mysql_ok‘, 1)          #这里被中断只循环了一次

********************

(‘Mysql_ok‘, True)

(‘Mysql_ok‘, True)

(‘Mysql_ok‘, True)

++++++++++++++++++++

(‘Mysql_ok‘, True)

(‘Mysql_ok‘, True)

(‘Mysql_ok‘, True)

True

[root@10.144.5.223 root]#

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值