1.for Loop: For (initialization of the loop variable 1; loop condition 2; Change of loop variable 3) {
Circulation Body 4;
}
The order of execution is: 1,2,4,3,2,4,3,2,4,3,2,4,3 ..... End loop when 2 is False
2.break: Jump out of this layer loop, continue skip this cycle, do not execute the following statement directly to the next loop.
3. Use of three cycles:
1. Feature 1 differs from feature 3, preferred while
2. Feature 1 is the same as feature 3 when Do...while is preferred
3. Number of fixed cycles preferred for
4. Loop nesting:
1. Loop in the loop, the general multi-line queue use, the outer control row, the inner control column.
2. Execution rules: Outer walk once, inner layer cycle all the time,
3. It is suggested that the less nested loops, the better, can use a layer of 2 layers, can use two layers without three layers.
4.break can only jump out of a layer of loops
5. Program = data structure + algorithm
Data structure: How to store and manipulate
Algorithm: Steps/processes to solve the problem (order, branch, Loop)
A well-designed and reasonable data structure can lead to good algorithms
-----------first design the data structure, and then the algorithm.
6. Arrays
1. Is a data type, reference type
2. Collections of the same data type
3. Definition of the array:
int [] A = new int [10];
4. Initialization of the array:
int [] A = {n/a};
int [] A = new int[]{1,2,3};
5. Access to arrays:
1. The array length can be obtained by using the array name. length
2. Use subscript to access array elements, subscript starting from 0, Max to Length-1
6. Traversal of the array:
int [] a =new int[10];
for (int i =0;i<a.length;i++) {//traversal array
a[i]=i;//Array Assignment
}
Loop structure and array of Java basics