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.