Cyclic structure
The function of the loop structure is to make the computer perform the same operation repeatedly
Various loop structures in C language
- for loop
The for loop is a more commonly used loop, the general form is
for(一般表达式; 条件表达式; 末尾循环体){循环体}
Execution logic:
Example: Print 1 2 3 4 5 …. 99 100 on the screen
#include <stdio.h>
int main()
{
int i;
//在屏幕上打印1-100
for(i=1; i<=100; i++)
{
printf("%d ",i);
}
return 0
}
- while loop
while(条件语句){循环体}
Execution logic
Example: Print 1 2 3 4 5 …. 99 100 on the screen
#include <stdio.h>
int main()
{
int i = 1;
while(i <= 100)
{
printf("%d ",i);
i++;
}
return 0;
}
End
The most basic structure of the cycle will stop here, the same branch structure and the loop structure can be 嵌套
used, cyclic structure typically used with a branched structure and to achieve complex functionality. Here is just a brief statement of the two branch structure