Python can cause a loop to break if it is return in the while loop

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.