using System; using System.Collections.Generic; using System.Linq; using System.Text; /* * .NET入门(九)测试各种循环结构 * * 老紫竹研究室 www.laozizhu.com * 分享软件开发的快乐与收获 */ namespace ConsoleApplication1 { class TestLoop { static void Main(string[] args) { testFor(); testWhile(); testDo(); } // 测试循环 // 顺便看到static可以和public交换位置 static public void testFor() { for (int i = 0; i < 5; i++) { Console.WriteLine("For " + i); } } // 测试While循环 static public void testWhile() { int i = 0; while (i < 5) { Console.WriteLine("While " + i); i++; } } // 测试 do while循环 public static void testDo() { int i = 0; do { Console.WriteLine("Do " + i); i++; } while (i < 5); } } } 运行结果 原文地址: http://www.laozizhu.com/view.jsp?articleId=257