C#中foreach,for,while,Do-While循环
2011-02-22 17:16
471 查看
foreach循环 // An array of integers int[] array1 = {0, 1, 2, 3, 4, 5}; foreach (int n in array1) { System.Console.WriteLine(n.ToString()); } // An array of strings string[] array2 = {"hello", "world"}; foreach (string s in array2) { System.Console.WriteLine(s); } for循环 // An array of integers int[] array1 = {0, 1, 2, 3, 4, 5}; for (int i=0; i<6; i++) { System.Console.WriteLine(array1[i].ToString()); } // An array of strings string[] array2 = {"hello", "world"}; for (int i=0; i<2; i++) { System.Console.WriteLine(array2[i]); } while循环 // An array of integers int[] array1 = {0, 1, 2, 3, 4, 5}; int x = 0; while (x < 6) { System.Console.WriteLine(array1[x].ToString()); x++; } // An array of strings string[] array2 = {"hello", "world"}; int y = 0; while (y < 2) { System.Console.WriteLine(array2[y]); y++; } Do while循环 // An array of integers int[] array1 = {0, 1, 2, 3, 4, 5}; int x = 0; do { System.Console.WriteLine(array1[x].ToString()); x++; } while(x < 6); // An array of strings string[] array2 = {"hello", "world"}; int y = 0; do { System.Console.WriteLine(array2[y]); y++; } while(y < 2);
相关文章推荐
- C#中foreach,for,while,Do-While循环对比
- C#中foreach,for,while,Do-While循环
- C#循环while、do...while、for、foreach
- C# 循环结构while,do-while和for的区别以及跳转语句
- C#分别使用for,while,do-while循环方法求的n!
- C#中for,foreach,while等循环的一个缺点
- C#基础(4)——break语句、continue语句、while循环、do-while循环、for循环、foreach循环
- PHP中的循环while、do...while、for、foreach四种循环。
- 浅谈php中的循环while、do...while、for、foreach四种循环
- C#中循环语句:while、for、foreach的使用
- JavaSE (七)循环控制语句:while、do....while、for,break和continue用法
- JAVA004--3种循环对比,for;while;do{}while
- 对比C#中for和foreach循环的性能
- 循环语句(for;while;do -while)
- Java 循环结构 - for, while 及 do...while
- javascript 循环语句 while、do-while、for-in、for用法区别
- 【MySQL】MySQL PLSQL Demo - 006.循环(WHILE DO and FOR LOOP)
- 【Java学习笔记之六】java三种循环(for,while,do......while)的使用方法及区别
- Java中循环有三种形式 while、do-while 和 for
- [置顶] Oracle三种循环:for,while,do...while(PL/SQL)