Getting Started with Python (iv) Looping statements

Source: Internet
Author: User
Tags terminates

Python provides a while loop with a for loop, noting that do...while loops are not provided.

The loop control statements are:

1) Break: Terminates the current loop and exits the entire loop body;

2) Continue: Terminates the current loop, jumps out of this cycle, executes the next cycle;

3) Pass: Empty statement, in order to maintain the integrity of the program structure;


1. While loop:

While judging condition: Execute statement ...
Count = 0while (Count < 9): print ("Count =%d"% count) count++ print ("Exit")
# Wireless Loop while True:print ("while loop")

2. For loop: You can traverse any sequence of items, such as a list or a string.

For Iterating_var in Sequence:statements (s)
For the "Hello World": print ("Current letter:", letter) for I in range: print (i) fruits = [' apple ', ' ba Nana ', ' orange ']for fruit in fruits:print (fruit)


Getting Started with Python (iv) Looping statements

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.