C Language 3 Flow control structure: sequential structure, selection structure, cyclic structure.
Sequential structure
The simplest structure, without the need for keywords. The Yasuteru code sequence is executed step-by-step.
Select structure
(i) if simple to use
1) First structure: if
A) If the condition is true, the following statement is executed, otherwise it is not executed.
if (condition)
{
Statement 1;
Statement 2;
}
2) Second structure: If-else
A) If the condition is true, execute statement 1, otherwise execute statement 2.
if (condition)
{
Statement 1;
}
Else
{
Statement 2;
}
3) The third kind of structure: if-else if-else ...
A) First judge the condition 1, if set up to execute statement 1, others do not, if the condition 1 is not established, then check the condition 2, "note" If the condition 3 is established, then the preceding is not established. Only one of all statement blocks will be executed.
if (condition 1)
{
Statement 1;
}
else if (condition 2)
{
Statement 2;
}
else (condition 3)
{
Statement 3;
}
(ii) Selection of structural-switch
Switch (value)//is usually a variable
{
Case value 1:
Statement 1;
break;
Case Value 2:
Statement 2;
break;
Case Value 3:
Statement 3;
break;
Default:
Statement 4;
break;
}
Explanation: The structure compares the value to the value 1, and if it is equal, executes all subsequent statements until the break statement jumps out of the entire loop, and if none of the preceding conditions is satisfied, the statement following the default is executed. If the break statement is not written, subsequent statements are executed consecutively until the break statement is encountered or all statements are executed , and the subsequent judgment is ignored if the preceding conditions are true.
C-Language Process control structure-sequential structure, selection structure