First, what is a cycle?
Executes a code snippet repeatedly when the condition is met
What are the conditions that make up a cycle?
1) Conditions for circular exit
2) loop body (repeated code snippet)
3) Let the loop normal exit condition meet the Code
What kinds of loops are there in C language?
While loop
Do...while Cycle
For loop
Two, 1, while loop
Format:
while (expression) {
Statement Block 1;
}
2. Use
int i=0;
while (i<5) {
printf ("%d\n", I);
i++; 1 2
}
3, Trap while dead loop (loop condition is always true) problem
int a=1;
while (a) {
printf ("xx\t");
}
4, while loop to use the attention point:
1) while (not 0 of the number) dead loop
2) while (3==num)
3) can omit curly braces (while loop body only a sentence)
Special note:1> after the IF, while and for statements, if followed by a line of statements, the same plus {}
The difference between the 2>do while and while is that the while is to judge the condition after the execution of the statement block, do is executed first after the judgment, so when the condition is false, while performing 0 loop body Dowhile will execute 1 cycles of the body
Third, for loop use
1,for Loop format
The first form of the 1>for cycle
for (int i=n;i>=1; i--) {
Ji=ji*i;
}
2>, second form: omit expression 1
int m=n;
for (; n>=1;n--) {
Ji *= N;
}
3>, third form: ellipsis expression 1 and expression 3
int m=n;
for (; n>=1;) {
Ji*=n;
n--;
}
4>, for (;;) {} This is a dead loop
2,for Loop Nesting issues:
For loop nesting the output of the first level control row, the second row controls the output of the column
Four: Break and continue use
Break is used only in the loop structure to indicate a stop loop (in a multi-layered loop, a break statement jumps only one layer out)
The Continue is used only in the loop structure, indicating that the loop is closed and the next loop is resumed.
C-Language loop control statements