while 循环
while (true) //循环的判断条件,如果条件为真就进入循环体,直到为假跳出循环
{
Console.WriteLine("world");
break ;
}
//控制循环次数
int i = 1;
while (i > -1)
{
Console.WriteLine(i);
i--;
}
break 跳出整个循环
continue 跳出当前循环,还会进入下一次循环
int j = Convert.ToInt32(Console.ReadLine());
int kk = 0;
while (j != 1)
{
if (j % 2 == 1)
{
j = 3 * j + 1;
kk++;
Console.WriteLine(j);
}
else
{
j = j / 2;
kk++;
Console.WriteLine(j);
}
}
Console.WriteLine(k);
for循环
int m = Convert.ToInt32(Console.ReadLine());
int nn = Convert.ToInt32(Console.ReadLine());
for (int k1 = 0; n < m; nn++)
{
if (nn % 17 == 0)
{
k1 += nn;
Console.WriteLine(k1);
}
}
do...while 多执行一次
int k2 = 0;
do
{
Console.WriteLine("111");
k2++;
} while (k2 != 1);