Python Learning Notes (iv)

Source: Internet
Author: User

While General syntax
While control condition: EXECUTE statement
The execution statement is executed until the control condition is false.
• Infinite Loops
While True: Execute statement
It is very dangerous to be able to execute the process all the time, and we will only see them on certain occasions. For example, some servers need to listen to a client every minute of the time to connect. These clients may make requests to the server at any time, so it is necessary for the server's listener to remain on standby.
• Counting Cycles
This is the most common statement that uses counters to determine when a loop terminates.
Count = 0;while Count <:    Print count    count + = 1
The range () function requires one, two, or three parameters to be supplied
Range (start, end, step)
If step 1 can be omitted, there are two parameters at this time
If there is only one parameter, the default start counts from 0
The Len () function returns the number of elements of a sequence
For loop
Movies = ["Avata", "Xman", "Titannic", "The Dark Knight Rises", "Jurassic Park", "Dances with Wolves"]for movie in Movies:    print Moviefor item in range (Len (Movies)):    Print Item, ":", Movies[item]

Break&continue as in C, break is breaking out of this layer, while continue is not continuing to execute the following code, jumping back to loop to perform the next loop
For I in range:    if i = = 6: Break    Print i,for i in range:    if i = = 6:        Continue    Print I,

Python Learning Notes (iv)

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.