First, we will introduce the IF-else Condition Statement. If statements are used to selectively execute specific expressions based on their authenticity. Program Block to control the process of the program. Use the same language as Java. For else if, there is an abbreviated Elif method.
For example:
CopyCode The Code is as follows: if x> 3:
Print ("Greater ")
Elif x = 3:
Print ("EQ ")
Else:
Print ("small ")
Next we will introduce the while statement. The while statement repeats a specific program block when the condition expression is true.
First, let's take a look at the sample program and then explain it:Copy codeThe Code is 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, it will be executed repeatedly. Compared with C/C ++/Java, the else statement is special. Here, else is an optional statement. When the conditional expression is false and jumps out of the while loop, the program block under the else statement is executed.
Finally, let's take a look at the for loop. For... In is another type of loop statement in Python. The main purpose is to iterate the Access Object Sequence. The usage is as follows:Copy codeThe Code is as follows: for X in range (1, 5 ):
Print (X)
Print ('over ')
For Loop statements, you must use the methods to jump out of the current loop and exit the loop. in Python, use the continue and break statements. The use of these two syntaxes is the same as that of C/C ++/Java.
With the above three methods, you can complete all the process control work in python!