Process control statement structure:
1. Sequential structure
2. Branch Structure:
if… Else series, switch.. A case series
3. Loop structure: Some statements that need to be repeated
(1) the for loop
for(;;) {loop body blocks, that is, code that needs to be executed repeatedly; } for(initialize expression; Cyclic condition expression; Iterating expression){loop body statement block, that is, code that needs to be executed repeatedly; }Copy the code
- Two for loops; Must write, no more, no less
- Initialize an expression, usually by declaring a loop variable, and initialize
- The expression of a loop condition is used to control the end of the loop. If the condition is true, the loop can be used; if the condition is not true, the loop should be ended
- An iterative expression used to modify the value of a loop variable
- Execution process :(1) first execute the initialization expression (2) judge the loop condition expression, if the condition is true, continue the loop, otherwise end the loop.
- (1) The body statement of the for loop may not be executed once, that is, the first judgment condition is not valid; (2) The for loop may loop indefinitely, the loop condition may not be written, or the condition may never hold.
- Break: Indicates the end of the current loop in switch
(2) the while loop
We can consider using a while loop when the number of loops is not obvious and only the conditions of the loop are known. You can also use “for”.
Grammatical structure
While (loop condition){loop body statement block; }Copy the code
Note:
- The loop condition written in while() must be Boolean; if true, the loop body is executed; otherwise, the loop is terminated
- While () does not follow;
Execution process:
- The while() loop executes {} if the condition is true; otherwise, it terminates.
- After executing the body block, return to 1
Remind:
- The body of a while loop may not be executed at all.
(3)do… The while loop
When this scenario is encountered: the loop body is executed at least once. Consider using do… while
Grammatical structure:
Do {loop body statement block; }while(loop condition); // Don't forget the semicolon after while()Copy the code
Description:
- While if the condition is true, repeat the body of the loop. If the condition is not true, end the loop
- While (loop condition); Behind;
Execution process:
- Execute the loop body block in do{} once
- Then judge the condition of the while. If the condition is true, continue, otherwise end
- If true, execute the loop body block in do{} again, then repeat 2 and 3
Remind:
-
do… The body block of the while structure executes once anyway, at least once.
break:
(1)switch
(2) Loop: for,while,do… The while. Function: Ends the current switch or loop
Continue :(rarely used in actual development)
It can only be used in loops
Role: To end this cycle early and continue the preparation for the next cycle (e.g., conditional judgment)
The idea of shortcuts
Error message: Alt + Enter
Quickly copy down a line: CTRL + D
Delete a row (select row) :
CTRL + X (Cut)
CTRL + y (Delete)
To pop up the search box: Double-click Shift
Switch two lines of code: CTRL + Shift +↑/↓
Note:
Single-line comment: CTRL + /
Multi-line comments: CTRL + Shift +/
(Press Cancel again)
Quick formatting: CTRL + Alt + L
Automatically declare variables: CTRL + Alt + V
Rename variables, methods, etc:
shift + F6
Rename a class:
alt + enter
Or click refactor->rename on the. Java file
Capitalization of whole words:
ctrl + shift + U
Shortcut template for code:
-
The main or PSVM
public static void main(String[] args) {} Copy the code
-
sout
System.out.println(); Copy the code
-
fori
for (int i = 0; i < ; i++) { } Copy the code
-
Customize shortcut templates
Editor – > Postfix Completion;
Editor -> Live Template (define -> Java application in Java) custom templates
Debug: code debugging
I have a bug.
Single step debugging:
-
Set the breakpoint
Breakpoint: The program stops at a breakpoint
-
Run, select Debug to run
-
Select the corresponding button
-
Step Over: Run this line (F8)
Step Into: Goes Into the called method
(The red one is generally used for source code, force-entry; Usually debug your code in blue.)
Step out: Step out from the trace method (shift + F8)
Resume Program: From previous breakpoint to next breakpoint (F9)
Stop “Class name” : stop debugging
Cancel all breakpoints: the red dot has a slash