Looping structures with arrays in C # (5)

Source: Internet
Author: User

First, the cycle structure

1. While

A. Syntax while (conditional expression) {

... Loop body (circular operation)

Write code to change the conditional expression from true to False to end the loop

}

Attention:
Conditional expression, must be a Boolean type (True\false)

B, Characteristics: first judgment, recycling, there may be 1 cycles are not

    

2, Do...while

A. Syntax

bo=

... Loop body (circular operation)

Write code to change the conditional expression from true to False

End Loop

}while (conditional expression);

    

Note: The conditional expression must be of type Boolean (True\false)

B, Characteristics: First cycle 1 times, then judge, at least 1 times cycle

One, C # array
1. What is an array?
A collection of "multiple" values for a specific "same data type"

2. What are the functions of arrays?
Save data

3, one-dimensional array declaration, assignment, use
1. Disclaimer
data type [] array name;
2. Assigning values
2.1 data type [] array name ={A list of values separated by commas};
2.2 data type [] Array name = new data type [list of]{values separated by commas};
2.3 data type [] Array name = new data type [a list of length]{values separated by commas};
The length must be equal to the number of values in the {}

2.4 In addition to 2.1, 2.2 and 2.3 of these 2 ways, first declared, after the line is changed to assign value

3. Use

3.1 The length of the array--the array name. Length

3.2 Gets the array name of a single value [subscript or index]; Subscript or index starting from 0

3.3 The value of the last 1 elements: array name [array name]. LENGTH-1]

3.4 value of each element in the output array

Prioritize the use of a For loop or foreach Loop

for (int i=0;< array name. length;i++) {

Console.WriteLine (array name [i]);

}

3.4 Assigning values to elements in an array

Array name [subscript]= value;

Second, the Circulation structure "P52 page Experience part"
1, while and Do...while, application in the number of cycles uncertain
While, first judge, then cycle, there may be 1 cycles are not
Do...while, first cycle 1 times, then judge; cycle at least 1 times

2, for Loop, the application in the case of the number of cycles has been determined "generally for the operation of an array"

2.1 Syntax:
For (① initial part; ② condition judgment; ③ Iteration part)
{
④ .... Loop body (circular operation)
}

2.2 Execution order
1th Cycle: ①②④
2nd time ... End of cycle: ③②④
3. Foreach Loop--the value of the output array or collection
Grammar:
foreach (data type variable name in array or collection)
{
Console.WriteLine (variable name);
}
Attention:
The data type must be consistent with the type of the array or collection in the Foreach Loop body, and the value of the element cannot be changed

Looping structures with arrays in C # (5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.