One, jumping out of the two key words of the cycle
1.break and Continue.
These two keywords are generally used in loops of curly braces.
break--ends the entire loop.
continue--ends the cycle and enters the next cycle.
Case of break:
int i = 1;
for (;;)
{
if (i>100)
{
Break
}
Console.Write (i+ "\ t");
i++;
}
Continue's case:
for (int i = 1; i <=; i++)
{
if (i%2 = = 0)
{
Continue
}
Console.Write (i + "t");
}
2.while Cycle
Initial
while (loop condition)
{
Loop body
Change Status to
}
Case:
int i = 1;
int count=0; Record the number of numbers associated with 7
while (i<=100)
{
if (i%7==0 | | i%10==7| | I/10==7)
{
Console.Write (i+ "\ t");
count++;
}
i++;
}
Console.Write ("A total of" +count+ "with 7 related numbers");
3.do...while (cyclic conditions) seldom used
The loop is executed once even if the initial conditions do not meet the loop condition.
Execute at least once.
Second, array: Solve the same kind of large amount of data in memory storage and operation functions.
Categories: one-dimensional arrays, two-dimensional arrays, multidimensional arrays.
Features: continuous, same class of data.
1, one-dimensional arrays:
Definition: Specifies the type, specifies the length, and specifies the name.
Int[] A = new int[5]; 5 is the length. Counting from 1 onwards. The default 5 element initial value is 0.
Int[] A = new Int[5] {90, 95, 89, 76, 99};
Int[] A = new Int[5] {90, 95, 89}; There is a syntax error, and the value after initialization must be 5.
Int[] A = new int[] {90, 95, 89, 76, 99}; The computer calculates the length of the array dynamically based on subsequent assignments.
Assignment value:
Array name [subscript value] = value;
Int[] A = new int[5];
A[0] = 10;
A[1] = 20;
A[2] = 30;
A[3] = 40;
A[4] = 50;
Value:
Array name [subscript value];//the subscript value starts at 0.
Console.WriteLine (A[3]+a[0]);
The benefits of arrays:
1. For large amounts of data, when saving, define an array to solve.
2. Using loops to control the subscript of an array, you can perform batch operations on arrays.
For example:
Int[] A = new int[5];
Batch assignment of arrays
for (int i = 0; i < 5;i++)
{
A[i] = (i + 1) * 10;
}
The batch value of the array.
for (int j = 0; J < 5;j++)
{
Console.WriteLine (A[j]); 0 subscript.
}
Case one: Do a coaching program that scores 6 players.
Define an array to save player scores
Int[] A = new int[6];
Input
for (int i = 0; i < a.length; i++)
{
Console.Write ("Please enter" + (i+1) + "Player's score:");
A[i] = Convert.ToInt32 (Console.ReadLine ());
}
Output
for (int j=0;j<a.length;j++)
{
Console.WriteLine ("+ (j+1) +" Player score is "+a[j]+" points. ");
}
C#. 4 arrays