C conditional statement circular statement of if while

  • 2020-06-15 10:07:45
  • OfStack

1. Three structures of the program

Sequential structure
Branching structure
Loop structure

Conditional statement

The if statement is one of the most useful control structures. if... else... The syntax of the statement:
if (Boolean expression)
The statement that performs the operation
or
if (Boolean expression)
The statement that performs the operation
else
The statement that performs the operation
Format of switch statement:
switch (Control expression)
{
case constant expression 1: statement group 1;
[break;]
case constant expression 2: statement group 2;
[break;]
...
case constant expression n: statement group n;
[break;]
[default: statement group n+1;[break;]]
}
The input parameters in switch () can only be integers or characters (including strings), not real (floating point) Numbers

Example:


if ( booleanExpression )   
statement-1;   
else   
statement-2; 

3. Loop statements

The syntax format of the while loop:
while (Conditions)
{
Statements that need to be looped;
}
Before I explain how to use the while loop, let me make a comparison with the if statement:
while (Conditions)
{
Statements that need to be looped;
}
if (Conditions)
{
The statement executed when the condition is true;
}
Flow chart of the while cycle
do... The grammatical structure of the while loop:
do
{
Statements that need to be looped;
}
while (conditions);
for cycle
foreach loop: Care only about the individuals in the set, not the number
Application of continue and break in loops
Sometimes, when executing a loop, you might want to exit the loop when the loop body is 1/2 full, rather than waiting until the loop condition is determined. At this point, you can apply one keyword --break.
Continue: Go ahead, close the current loop and enter the next one
Break; Brake, break. Close the loop


Related articles: