1.while Cycle Structure
Grammar:
while (loop condition) { // loop Action }
While loop structure Flowchart:
Example:
1 int i = 1; 2 while (i <=) {3 System.out.printlen ("good study"); 4 i + +; 5 }
Note: The content in the parentheses after the keyword while is the while loop condition. A loop condition is an expression whose value is a Boolean type, that is, ture or false. The statements in {} are collectively referred to as circular operations, also known as loop bodies.
The structure of the while loop structure is executed in the following order:
1) Declare and initialize the loop variable
2) determine if the loop condition is satisfied, if satisfied, then perform a cyclic operation, or exit the loop
3) After performing the loop operation, judge the loop condition again, decide to continue the loop or exit the loop
A feature of the while loop: first judgment, then execution.
2. Do-while Cycle
Grammar
Do { // loop Action } while (cyclic conditions);
Flowchart of the Do-while cycle
Example:
1 int i = 1; 2 Do {3 System.out.println ("good study"); 4 i++; 5 }while (i <= 100);
Note: The Do-while loop structure ends with a semicolon.
The execution order of the Do-while loop is generally as follows:
1) Declare and initialize the loop variable
2) perform the cycle operation again
3) Determine the loop condition, if the loop satisfies the condition, then the loop continues execution, otherwise exits the loop
Characteristics of Do-while cycle: first execution, after judgment.
3.for Cycle
Grammar:
for (expression 1; expression 2; expression 3) { // loop Body }
Expression 1: An assignment statement
Expression 2: Conditional statement
Expression 3: An assignment statement
The loop structure in Java