The fifth chapter design of the selection structure
The first part:
Summarize
1 A program structure that uses different program segments to process a certain condition is called a selection structure.
2 C-language selection statements include if and switch statements
3 Use the break statement to interrupt the execution of the switch statement.
4 using the goto statement, the program execution process can be unconditionally specific.
Part II:
Separate description
5.1 Select Structure program with IF statement design
5.1.1 a simple if statement
Conditions of use: meet the conditions on the execution, not satisfied will not be executed.
Format:
If (expression) {statement 1}
5.1.2 If_else Statements
Format:
If (expression 1) {Statement 1}
(Expression 2) {Statement 2}
5.1.3 Nested IF statements
Form 1:if (expression 1)
If (expression 2) statement 1
Else Statement 2
Else Statement 3
Form 2:if (expression 1) {
if (expression 2) statement 1
}else Statement 2
Form 3:if (expression 1) Statement 1
else if (expression 2) Statement 2
Else Statement 3
5.2 Designing a multi-branch structure program with switch statements
5.2.1switch statements
Format:
switch (expression)
case constant Expression 1: statement 1 (break;)
Case constant Expression 2: statement 2 (break;)
Case constant Expression 3: statement 3 (break;)
....................................
case constant Expression N: statement n (break;)
Default: Statement n+1
5.2.3 Nested SWITCH statements
5.3 Unconditional Turn statement (GOTO)
Format:
S
Goto S;
Add:
1: Digit: g=n%10
2:10-bit: s=n/10%10
3: Hundred: b=n/100%10
4: Thousand: q=n/1000%10
Program Design Basics Chapter fifth programming of selection structure (knowledge point)