int[] numbers = { 1, 2, 3, 4, 5 };
foreach (int number in numbers)
{
Console.WriteLine("当前数字为: " + number);
}
2.for循环
for (int i = 0; i < 5; i++)
{
Console.WriteLine("当前数字为: " + i);
}
while 循环的示例:
int i = 0;
while (i < 5)
{
Console.WriteLine("当前数字为: " + i);
i++;
}
do-while 循环的示例:
int i = 0;
do
{
Console.WriteLine("当前数字为: " + i);
i++;
}
while (i < 5);