◇ Design of selection structure
1.if statement:
The IF statement is the simplest and most intuitive way to implement a selection statement. His simple form is to determine if a condition value is true and, if true, to execute a piece of code.
if (expression) {
Statement 1
}
Function: Evaluates the value of the expression and, if true, executes statement 1; otherwise skips statement 1 executes the next statement of the IF statement.
Description: The expression in parentheses controls the condition in which the value of the expression is nonzero to true, and 0 is false.
2.if_else statement:
if (expression) {
Statement 1
}else{
Statement 2
}
Evaluates the value of the expression, if the value of the expression is true, executes statement 1, and skips statement 2, continuing to execute the next statement of the IF_ELSE statement;
If the value of the expression is false, skip statement 1, execute Statement 2, and proceed to the next statement of the If_else statement.
3. Nested IF statements:
A.If (expression 1) {
if (expression 2) {
Statement 1
}else{Statement 2}
}else{Statement 3}
b.if (expression 1) {
if (expression 2) {
Statement 1
}
}else{Statement 2}
C.if (expression 1) {
Statement 1
}else if (expression 2) {
}else{
}
4.switch statement:
switch (expression) {
case constant Expression 1: statement 1
Case constant Expression 2: statement 2
Case constant Expression 3: statement 3
....
case constant Expression N: statement n
Default: Statement n+1
}
The value of the expression is evaluated first, followed by the constant expression, and, if equal to the constant expression I, executes from the expression I until the switch statement ends.
If all constant expressions are not equal, execution starts from default.
Description
1). Switch is followed by a constant or constant expression or an expression that evaluates to a result, with its integer part compared to each constant expression.
2). A constant expression cannot have a variable, and the type must be an integer character or an enumerated type, and each constant expression is different.
3). The default statement usually appears after the case statement, or it can be between.
5.break statement:
Break
Terminates execution of the switch statement or Loop statement in which it resides.
6.goto statement: (strongly discouraged, he destroys the logical order of the program)
C Language Basics 3