Python loop for while, Process control if statement

Source: Internet
Author: User

1. If statement

The code is as follows Copy Code
i = 10
n = Int (raw_input ("Enter a number:")
If n = i:
Print "Equal" El
If n < i:
Print "Lower"
Else
Print "Higher"

2. While statement

The code is as follows Copy Code

While True:
Passelse:
Pass

#else语句可选, the Else statement is executed when the while is false. Pass is an empty statement.

3. For loop for ... In

The code is as follows Copy Code
For I in range (0, 5):
Print Ielse:
Pass

# Print 0 to 4


Note: Executes the ELSE statement when the For loop ends;
Range (A, B) returns a sequence, starting from A to B, but excluding b,range the default step is 1, you can specify a step, range (0,10,2);
4. Break statement
Terminates the loop statement, and any else that corresponds to the loop is not executed if it is terminated from a for or a while.
5. Continue statement
The continue statement is used to tune the remaining statements of the current loop, and then proceed to the next round of loops.

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.