Learning Essentials
- While loop
- Do-while Cycle
- For loop
Loop what is the feature of the Loop loop
While loop syntax analysis
Case
The teacher every day to check the learning task is qualified, if not qualified, then continue.
The teacher assigned to Xiao Qiang every day of learning tasks: the morning reading materials, learning theory part, the afternoon machine programming, master the code part.
Case analysis
- Analyze if there is a duplicate operation
- Using the While loop implementation
-
- Determining loop conditions and looping operations
- Apply while syntax to write code
- Checks if the loop can exit
-
- Input string from console: Scanner input () method
- String equality comparison: "Str1". Equals ("str2")
- "= =" Can I compare strings? New String ("str") and "str"?
On-Machine Exercise: Complete the code implementation of this case
Program debugging
- There are sometimes errors in the process of writing programs, but there is no good way to find and locate errors.
Solution One: Read the code and add the output statement
Solution Two: Program debugging
- Demo Example: Using the while loop output variable i,i<4, expect to output 5 digits, Debug.
On-Machine Exercise: Complete the demo example and master the program debugging method.
Analysis on the structure of do-while cyclic grammar
Problem
After several days of study, the teacher gave Kaylee a test question,
Get him to write the program first.
Then the teacher checks whether it is qualified. If it is not qualified, continue writing. ......
Problem Analysis Demo Example: code implementation
Comparison of While loops and do-while loops
Different syntax
Different execution order
When the initial condition does not meet the cycle condition
- The while loop does not execute at once
- Do-while cycle is performed at least once in any case
On-Machine Exercise: Complete the Student Information management System main Menu loop input, input errors can continue to enter, until the correct menu to choose, exit the main menu. (except the Exit Function).
Why does A for loop use a for loop
For loop syntax structure
Note: For the use of expressions in the for loop, 1 parameters and 3 parameters support multiple expressions
Continue and break usage and differences
- Continue: End the cycle and go to the next round.
- Break: Terminate loop operation
Nested structures of loops
- Typical three loops support nested loop structures
- In actual development, loop nesting does not exceed triple
On-Machine Exercise: Use the For loop to output the sum of odd numbers within 1-100. On-Machine Exercise: Use the For loop to output the 99 multiplication table.
On-Machine Exercise: Use the For loop output isosceles triangle (high custom input for triangles).
On-Machine Exercise: Use the For loop to output a diamond.
JavasSE-04 Java Loop structure