Python can cause a loop to break if it is return in the while loop
[email protected] 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 ()
[[Email protected]4.5.223 root]#
[email protected] 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
[Email protected] root]#
This article is from the "Wish" blog, please be sure to keep this source http://xinyuan8.blog.51cto.com/677906/1640339
Python will cause a loop break if it is return in the while loop