---restore content starts---
First, the features of the FOR Loop statement:
1. Initial conditions: The first state of the cycle.
2, Cycle conditions: Under what conditions, not satisfied is terminated.
3, state change: Change the value of the loop variable.
4. Loop body: The part to be executed repeatedly.
All for loop instructions are inseparable from these.
Second, for the form and use of the loop:
The form of a loop:
1, (1), for (initial condition ; cyclic condition ; State change)
int i;
for (i = 1; i <=; i++)
{
Console.Write (i+ "\ t");
}//Result output number 1 to 100
(2), for (; cycle conditions ;)
int i=1;
for (; I <= 100;)
{
Console.Write (i+ "\ t");
i++;
}//result is also output number 1 to 100
(3), for (;;)
int i=1;
for (;;)
{
Console.Write (i+ "\ t");
i++;
}//program is a dead loop program
Use of loops:
1. Find the number within 100 and 7 related. (Can be divisible by 7, single digit is 7, 10 digits is 7)
for (int i=1;i<=100;i++)
{
if (i% 7 = = 0 | | I% = = 7 | | i/10 = = 7)//Key
{
Console.Write (i + "t");
}
}
2. Display the ASCII code of the computer:
for (int i=0;i<=125;i++)
{
Console.Write (i+ "=" + (char) i+ "\ t");
}
Three, the attention matters:
1. The parentheses behind the for is separated by semicolons by three items.
2, for the back without a semicolon .
3. Do not write the cycle of death.
Iv. Nesting for loops:
int i,j;
for (i = 1; I <= 5; i++)
{
for (j = 1; J <= 5; j + +)
{
Console.Write ("*");
}
Console.WriteLine ();
}//Program output 25 *, horizontal 5, vertical 5.
---restore content ends---
First, the features of the FOR Loop statement:
1. Initial conditions: The first state of the cycle.
2, Cycle conditions: Under what conditions, not satisfied is terminated.
3, state change: Change the value of the loop variable.
4. Loop body: The part to be executed repeatedly.
All for loop instructions are inseparable from these.
Second, for the form and use of the loop:
The form of a loop:
1, (1), for (initial condition ; cyclic condition ; State change)
int i;
for (i = 1; i <=; i++)
{
Console.Write (i+ "\ t");
}//Result output number 1 to 100
(2), for (; cycle conditions ;)
int i=1;
for (; I <= 100;)
{
Console.Write (i+ "\ t");
i++;
}//result is also output number 1 to 100
(3), for (;;)
int i=1;
for (;;)
{
Console.Write (i+ "\ t");
i++;
}//program is a dead loop program
Use of loops:
1. Convert the number into ASCII code;
Three, the attention matters:
1. The parentheses behind the for is separated by semicolons by three items.
2, for the back without a semicolon .
3. Do not write the cycle of death.
Iv. Nesting for loops:
int i,j;
for (i = 1; I <= 5; i++)
{
for (j = 1; J <= 5; j + +)
{
Console.Write ("*");
}
Console.WriteLine ();
}//Program output 25 *, horizontal 5, vertical 5.
December 23 Loop statement (for)