Branch structure: If-else
An expression:
Statement block
Execution process: When the program executes to the IF statement, first of all to determine the true or false expression; If the value of the expression is true (true), the statement block is executed, and if the value of the expression is False (false), the statement block is skipped and execution continues down.
An expression:
Statement Block 1
Else
Statement Block 2
Execution process: When the program executes to the IF-ELSE statement, first of all to determine the true or false expression; If the value of the expression is true, the statement block 1 is executed, and if the value of the expression is false, then the statement block 2 after the else is executed.
If expression 1:
Statement Block 1
Elif Expression 2:
Statement Block 2
...
Else
Statement block N
Unlimited number of Elif
else can not write
1. Enter two integers to print a larger value
2. Enter three integers to print in order from small to large
3. Enter a three-digit number to print its digits, 10 bits, and hundreds
4. Enter a year, to determine whether it is leap years, is to print a word, not print another sentence
5. Enter an integer to determine whether it can be divisible by 3 and divisible by 5
Loop structure (while)
An expression:
Statement block
Execution process: When the program executes to the while statement, first of all to determine the true and false expression. When the value of the expression is true, the corresponding statement block is executed, then the while is returned while the expression is not true or false, and if the expression is true or false, the statement block is skipped.
An expression is also called a loop condition
A statement block is also called a loop body
Expressions have been established as dead loops
Break: Jump out of the loop
Continue: End this cycle and go to the next cycle
In conjunction with else use: loop exits normally, the statement block after the else is executed, and non-normal (break) exits without executing the ELSE statement block.
1
?
10:
print (i)
1
Break
Else
print (' end ')
1. Calculates the and of all integers between 1~100
2. Print character a~z
3. Print character Z~a
4. Loop input 10 characters, uppercase to lowercase, lowercase to uppercase, other characters not processed
5. Think: Can the loop be nested, think about its application scenario and the execution process
?