Flash programmer's understanding of while true in Python

Source: Internet
Author: User

When I get used to as and learn python, there are still some obstacles. For example, if I execute while (true) in as, it must be an endless loop, the establishment of the python socket is exactly like this:

Server = socket. socket (socket. af_inet, socket. sock_stream)
Server. BIND (ADDR)
Server. Listen (999)

While true:
Clientsock, addrs = server. Accept ()

Print "Client IP:" + STR (addrs [0])
Print "client port:" + STR (addrs [1])

I have been wondering this aser for a long time. Why does Python keep executing the loop body? Today, I had a small experiment and suddenly realized it. It turns out that while true is not in a non-stop loop in the socket connection, but after the first execution, the socket. accept () will be in the listening mode. When will the listening be connected and when will the next loop body be executed. If there is no connection, the next loop will not be executed. Now I understand it.

If you still don't understand it, try this experiment.

While true:
Print 'running'

The latter will output 'running' continuously on the screen'

Also remind aser that 'isflash' + 123 in python is incorrect. This indicates that python does not automatically perform forced type conversion when adding characters and numbers. It must be manually processed as 'isflash' + STR (123)

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.