Python Process Control Instance Code _python

Source: Internet
Author: User
First, introduce the IF-ELSE conditional statement. If statements are used to selectively execute specific program blocks based on the true and false expression, the process of the control procedure. Use the same languages as Java. For else if, there is a elif shorthand.
For example:
Copy Code code as follows:

If x > 3:
Print ("Greater")
elif x = = 3:
Print ("EQ")
Else
Print ("small")

Next, you introduce the while statement. The while statement acts repeatedly to execute a particular block of blocks when the conditional expression is true.
First look at a sample program, and then give a description:
Copy Code code as follows:

x = Int (Input ("Enter a integer:")
While x!=-1:
Print (x)
x = Int (input ("Next Number:")
Else
Print ("End")
Print (' over ')

In this code, as long as the value of x is not equal to-1, the execution is repeated. Relative to C/c++/java, the more special is the Else statement. Here, else is an optional statement. When the conditional expression is false, the program block below the Else statement is executed after jumping out of the while loop.
Finally, look at the for loop. For.. In is another kind of looping statement in Python. The main purpose is to iterate over the sequence of objects. Use the following methods:
Copy Code code as follows:

For x in range (1,5):
Print (x)
Print (' over ')

For circular statements, you need to have a way out of the current loop and out of the loop, in Python, using continue and break statements. For the use of these two grammars, the same c/c++/java, so do not repeat it more.
Using these three methods, you can do all of the process control work in Python!

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.