首页 > 代码库 > for循环 20140819
for循环 20140819
语句分为:
1、顺序语句
2、分支语句
3、循环语句
1)、初始条件
2)、循环条件
3)、循环体
4)、状态改变
穷举法
迭代法
例如:
for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10 - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= i * 2 - 1; k++)
{
Console.Write("★");
}
Console.Write("\n");
}
for (int a = 1; a < 10; a++)
{
for (int b = 1; b <= a; b++)
{
Console.Write(" ");
}
for (int c = 1; c <= 2 * (10 - a) - 1; c++)
{
Console.Write("★");
}
Console.Write("\n");
//兔子生小兔
int tu1 = 1, tu2 = 1, tu = 0;
for (int i = 3; i <= 48; i++)
{
tu = tu1 + tu2;
tu2 = tu1;
tu1 = tu;
}
Console.WriteLine(tu);