每天都进步的课堂随笔Day05
do while loop
- In terms of while grammar, if not meet the requirement, then cannot enter loop,but we don't need to meet requirements then execute for once time at least for sometimes.
- do while is a little bit likes while loop, the difference is the former will execute for one times at least
do{
//code sentence
}while(boolean expression);
-
the differences between while and do while
-
while is to judge then execute, do while is opposite.
-
Do...while always guarantee loop structure which will be executed for once time at least, this is mainly difference.
-
For loop
-
although all the loop could be expressed by while or do while, but JAVA offers another grammar----for loop which makes loop structures more simple.
-
The for loop statement is a generic structure that supports iteration and is the most efficient and flexible loop structure.
-
the executive times of for loop was confirmed before execution, and grammar style as follows:
for(initialized; boolean expression; update){ //code statement }
-
There are some statements of for loop
- the first step is to execute initialization , allowing state a kind of data type, and it could initialize one or more control variable of loop, and it could be empty.
- the second step is to verify the value of boolean expression, if it's true, then loop structure was executed, if false, it will end and execute the statement out of for loop.
- After executing loop for once time, updating the value of control variable(The iteration factor controls the increase or decrease of loop variables)
- Then verify boolean expression again, then keep repeating this process.
Break & Continue
-
Break was used for mainly body of any loop statement, all it could be applied in controlling process of loop.
-
Break is mainly used for exiting loop, dose not execute the left statement.(break also could be used in Switch statement)
-
Continue is used for ending loop process in loop statement structure, then skip the statement which has not been executed, and go on verifying if it is needed to execute next time.
JAVA Method Detailed Annotations(JAVA 方法)
- What is the method
- The definition and call of method
- Method overload
- Command line passes parameters(命令行传参)
- Variable parameters
- Recursion (递归)
Method(方法)
-
System.out.println()// System类 out对象 println方法
-
Java methods are collections of statements, they achieve a function together
-
Method is an ordered combination of steps to solve a class of problems
-
Method is included in Class or Subject
-
Method is created in program and cited in other places
-
-
The principle to design Method: Methods are meant to be functional blocks, Is a collection of statement blocks that implement a function. When we design our methods, it is best to keep them atomic, that is, a method does only one function, which is also good for later expansion