本文主要是介绍误解continue,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用continue,一直以为是跳到循环开始的地方,但是昨天的一段测试代码,发现自己以前的理解是错误的。
测试代码:
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int arg, char ** argv)
5 {
6 int s32Cycle;
7
8 s32Cycle = 10;
9
10 do{
11 s32Cycle--;
12
13 if(s32Cycle != 0)
14 {
15 printf("the cycle: %d \n", s32Cycle);
16 continue;
17 }
18 }while(0);
19
20 printf("end: %d\n", s32Cycle);
21
22 return 0;
23 }
2 #include <stdlib.h>
3
4 int main(int arg, char ** argv)
5 {
6 int s32Cycle;
7
8 s32Cycle = 10;
9
10 do{
11 s32Cycle--;
12
13 if(s32Cycle != 0)
14 {
15 printf("the cycle: %d \n", s32Cycle);
16 continue;
17 }
18 }while(0);
19
20 printf("end: %d\n", s32Cycle);
21
22 return 0;
23 }
运行结果:
the cycle: 9
end: 9
end: 9
continue应该是跳到循环条件判断的地方,而不是开始的地方。
这篇关于误解continue的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!