while和for可以相互转换例子

 1 //while和for循环可以相互转换,以下为简单格式;
 2 for(1;2;3)
 3      A;
 4 等价于
 5 1 6 while(2)
 7 {
 8     A;
 9     3;
10 }
 1 /*
 2   Name:while和for可以相互转换例子 
 3   Copyright: By.不懂网络
 4   Author: Yangbin
 5   Date:2014年2月18日 03:33:57 
 6   Description: 
 7 */
 8 # include <stdio.h>
 9 /*int main(void)
10 {
11     int i,sum = 0;
12     for(i=1;i<=100;++i)
13     sum+=i;
14     printf("%d\n", sum);
15     return 0;
16 }*/
17 int main(void)
18 {
19     int i = 1,sum= 0;
20     while(i<=100)
21     {
22         sum+=i;
23         ++i;
24     }
25     printf("%d\n", sum);
26     return 0;    
27 }
28 
29 /*
30 ----------------------
31 该代码由C-Free 5.0 编写并输出调试结果
32 -----------------输出结果---------------
33 5050
34 ------------结论------------
35 while和for可以互换,但是使用while时应
36 注意顺序,顺序为for循环的判断顺序。 
37 
38 */

 

posted @ 2014-02-18 03:43  不懂网络  阅读(2664)  评论(1编辑  收藏  举报