当前位置:网站首页>Detailed explanation of the execution order of the expression and loop body in the for loop

Detailed explanation of the execution order of the expression and loop body in the for loop

2022-06-24 12:25:00 PHP Development Engineer

For learning c To a friend ,for Loop may be a kind of loop statement that we often use

for( expression 1; expression 2; expression 3){ The loop body }

Knowing the execution order of its statements can avoid many mistakes for us

We can use the following small program to easily measure the internal statement cycle order :

#include<stdio.h>
void main()
{
int i;
for (printf("#1\n"),i=1;
  printf("#2\n"),i<=5;
  printf("#3\n"),i++)
{
    printf("hello\n");
}
}

It is not difficult to see from the above execution results for Except for the expression in the loop 1 To initialize variables , Its loop is an expression 2—— The loop body —— expression 3—— expression 2 This cycle .

The above article is correct for The detailed explanation of the execution sequence of expressions and loop bodies in the loop is all that Xiaobian has shared with you , I hope I can give you a reference , I also hope you can support the open source world .

Complete example :http://github.crmeb.net/u/defu

come from “ Open source world ” , link :https://ym.baisou.ltd/post/668.html, If you want to reprint , Please indicate the source , Otherwise, the legal liability will be investigated .

原网站

版权声明
本文为[PHP Development Engineer ]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/06/20210602165102383k.html