1.while Loop statement
Grammar
while (loop condition) {
Statement of the loop operation
}
Points:
Judge and execute first.
Variable cycle times
Avoid dead loops
2.do-while Loop Statements
Grammar
The while loop is also called the type loop
Do-while cycle, also known as the cycle
do{
Looping operation statements
}while (cyclic conditions);
Execute once to meet the loop condition continue execution
Points:
Perform the re-judgment first.
Execute at least once
Do not miss the last semicolon
3.for Loop statement
Grammar
for (expression 1; expression 2; expression 3) {
Condition satisfies execution
}
Expression 1: Parameter initialization
Expression 2: Conditional judgment
Expression 3: Updating the loop variable
Points:
Number of cycles determined
Comparison of While loops and for loops
Loop type
The while loop is an indeterminate type of loop
The For loop is a deterministic loop
Convert each other
While loops and for loops can be converted to each other
Use occasions
When the number of loops determines the thing, use the For loop
When the number of cycles is indeterminate, use the while loop
4. Double for Loop
Grammar
for (expression 1; expression 2; expression 3) {Outer loop
for (expression 1; expression 2; expression 3) {Inner loop
}
}
Parsing: A loop containing a circular statement in a loop is called a double loop,
When the outer loop once, the inner loop to loop, and then back to the outer loop into the next cycle, until the outer loop is finished.
5.break syntax and usage
Grammar
Break: Change the program flow, in the loop statement, to jump out of the loop and execute the following statement
Points:
End of Loop
Change the number of loop executions
Just jump out of this loop
6.continue syntax and usage
Grammar
Continue effect: Skips the cyclic weight remaining statement and executes the next loop
Points:
No end loop
No change in loop execution times
Works only in the loop of this layer
Java Basics (4) Looping statements