C语言for循环

for循环本来挺简单的,但是这几天教一个新手学习,让人抓狂,真的好难,下面是代码

 1 #include <stdio.h>
 2 int main()
 3 {
 4 
 5     printf("================第一种情况=======================
");
 6     /*c语言for循环几种情况:
 7     1、for循环的作用范围
 8     */
 9     int n=3;
10     for(int i=0; i<n;++i)
11     printf("hello
");
12     printf("world!
");
13     /*
14     上面的for循环作用到分号,所以hello的输出结果有3行,world输出是一行,
15     也就是说for循环只在第一个分号前有效,
16     注意:单独的分号也被视为一条语句。
17     */
18     printf("================第二种情况=======================
");
19     /*
20     加了大括号之后,for的作用范围扩大
21     */
22     n=3;
23     for(int i=0; i<n; ++i)
24     {
25         printf("hello
");
26         printf("world!
");
27     }
28     /*
29     输出结果:hello 和world!依次输出了三次,所以在大括号内都属于for循环的作用域
30     */
31     printf("================第三种情况=======================
");
32     /*
33     当for循环碰到if else 
34     */
35 
36     return 0;
37 }

================第一种情况=======================

hello
hello
hello
world!
================第二种情况=======================
hello
world!
hello
world!
hello
world!
================第三种情况=======================

原文地址:https://www.cnblogs.com/chuanyang/p/13889300.html