How to realize for cycle in C language
This article mainly introduces "how to realize for cycle in C language". In daily operation, I believe many people have doubts about how to realize for cycle in C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize for cycle in C language". Next, please follow the editor to study!
Take a look at the program first:
# include int main () {for (int I = 0; I)
< 5; i++) { printf("i = %d\n", i); } printf("Loop ended!\n"); return 0;} 运行结果: i = 0i = 1i = 2i = 3i = 4Loop ended! for循环的语句结构为: for(表达式1; 表达式2; 表达式3) { 语句; } 其执行顺序为: (1)执行表达式1 (2)执行表达式2。表达式2是一个判断语句;若为真,则执行{}中的语句。若为假,则结束for循环 (3)若表达2为真,执行表达式3 (4)执行表达式2 (5)不断重复步骤(3)和步骤(4),直到表达式2为假,结束循环。 流程图如下所示:
Program execution process:
For the first time, the value of I in expression 1 is 0; in expression 2, 0