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!