java learning day7

while loop
while (judgment condition) {
   loop body
}
If the judgment condition is true, execute the loop body, if not, do not execute the loop body


while loop expansion
Initialization statement
while (condition judgment statement) {
   loop body
   control condition statement
}
======= ===================================================== ====
do...while loop
do{
   loop body

while (judgment condition)
executes the loop body first, and then judges the condition. If it is true, continue to execute the loop body.
Regardless condition is true or not, the loop body executes the
extended format
initialization statement at least once;
do{
  loop body;
  control conditional statement;
}
while (conditional judgment statement)
===================================== =============================
For loops are generally used for finite loops, while loops are generally used for infinite loops
, knowing how many loops need to be looped use for loop
Use while loop when you don't know how many times you need to loop
======================================= =========================
break out of the entire loop
continue out of the current loop
The difference between break and continue:
break is only used in switch and loops, other places Meaningless
continue is only used in loops, meaningless in other places.
Although break and continue can end the loop, they can only end one layer of loops (the current loop).


If the if statement and the for loop have only one execution statement, you can omit the curly braces
== ===================================================== =========
Array
Reference data type
Array is a container for storing multiple variables, and the data types of these variables must be consistent.
Arrays can store both basic data types and reference data types
. Definition format:
1. Data type [] array name
2, data type array name []
initialization of array
1, static initialization: specify the initial value of each element during initialization, and the system determines the length of the array
data type [] array name = new data type []{ element1, element2,...};
data type[] array name={element1, element2,...};
int[] arr={3,5,7,9,11};
Each element in the array has a subscript, the first subscript starts from 0, and a[0] represents an
element . Assign an element to a variable to
traverse arr.length such as int x=a[1] to get the length of arr
for(int i=0;i<arr.length;i++){
   System.out.println(arr[i]) ;
}
Refer to the memory address of the data type reference data, operate on the memory address The memory address of the
array reference is the memory address of the first element
===================== =============================================
Collection
Traverse collection, use augmentation for loop (which can also traverse the array)
enhance the for loop format
for (the data type variable of the element: the name of the array to be traversed) {}
​​The elements in the array will be stored in the variable in turn.
Enhanced for loop features: it can only be used to traverse

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325824958&siteId=291194637