1.while
i=0;
while(i<100)
{
i++;
//i+=1;
Console.WriteLine("{0}",i);
}
Console.ReadKey;
2.do-while
i=0;
do
{
i++;
//i+=1;
Console.WriteLine("{0}",i);
}
while(i<100);
Console.ReadKey;
3.for
int sum = 0;
for(int i=0;i<100;i++)
{
sum += i;
Console.WriteLine("{0}",sum);
}
Console.ReadKey;
4.foreach
遍历数组,调用数组中的元素
int[] nums = new int[10];
for(int i,i<10,i++)
{
nums[i] = i;
}
int sum = 0;
//每次提取一个元素放到只读变量
foreach(int num in nums)
{
sum += num;
}
Console.WriteLine(sum);