1. Summary
1. Summary
From the process of program execution, programs can be divided into three basic structures: sequential structure, branch structure, and loop structure
The most basic unit of execution in a program is a statement. The statements in C language can be divided into five categories:
1) An expression statement can be formed by adding a semicolon to the end of any expression. The commonly used expression statement is an assignment statement.
(2)A function call statement is composed of a function call followed by a semicolon.
(3)Control statements are used to control program flow, consisting of specialized statement qualifiers and required expressions. There are mainly conditional judgment execution statements, loop execution statements, turn statements, etc.
(4)Compound statements consist of {} enclosing multiple statements to form a single statement. A compound statement is considered a single statement and can appear in all places where statements are allowed, such as loop bodies.
(5)Empty statements consist only of semicolons and have no actual function.
Relational expressions and logical expressions are two important types of expressions, mainly used for judging conditional execution and loop execution.
C language provides various forms of conditional statements to form branching structures.
(1)The if statement is mainly used for one-way selection.
(2)The if else statement is mainly used for bidirectional selection.
(3)If \ - else \ - if language and switch statement are used for multi-directional selection.
These forms of conditional statements are generally interchangeable with each other.
- C language provides three types of loop statements.
(1)The for statement is mainly used to give the initial value of a loop variable, the increment of the step size, and the number of loops in a loop structure.
(2)The number of loops and control conditions can only be determined during the loop process using while or do while statements.
(3)Three types of loop statements can be nested together to form multiple loops. Loops can be parallel but not crossed.
(4)Transfer statements can be used to move the process out of the loop body, but not from outside to inside the loop body.
(5)In a loop program, it is important to avoid dead loops by ensuring that the values of loop variables can be modified during runtime and gradually making the loop conditions false, thereby ending the loop.
- Summary of C language statements
name normal form
simple sentence expression statement;
Empty statement ;
condition statement if(expression) statement;
if(epression) statement 1; else statement 2;
if(epression 1)statement 1; else if(expression 2) statement 2…else statement n;
switch statement switch(expression){ case constant experssion: statement…default: statement; }
loop statement while statement
while(expression )statement;
for statement for(statement 1;expression2;expression 3)statement;
break sentence break;
continue sentence continue;
return sentence return(expression);