误解continue

来源:互联网 发布:java培训有必要吗 编辑:程序博客网 时间:2024/04/30 22:21
使用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 }

运行结果:
the cycle: 9
end: 9

continue应该是跳到循环条件判断的地方,而不是开始的地方。
原创粉丝点击