I. Process Control - Selection Structure
A. Process Control Structure
1. Introduction to the process signs
Process begins / ends
Judge and branch
Calculation procedure.
Connection
Input / output instructions
Process line
2. Introduction of Process Control Structure



Sequence Selection Loop
a. Sequential structure: Sequential structure refers to the structure in which the program executes each statement in turn from top to bottom without any judgment or jumping. The preceding examples all adopt sequential structure.
b. Choose structure: Choose structure to execute different code according to the result of condition judgment. The selected structure can be subdivided into single-branch structure, double-branch structure and multi-branch structure. Java provides if control statements and switch statements to implement the selection structure.
c. Loop structure: Loop structure is to execute a piece of code repeatedly according to the judgment condition. Java provides while statement, DO-WHILE statement, for statement to implement loop structure.
B. Selection Structure
1. "If"
a. There are three different kinds of "If" control statement.
- Single branch structure
- Double branch structure
- Muti-molecular structure
b. Using "If" for single branch structure
- Format:

c. Steps of Judge the result of the expression:
- Judge the expressed results.
- Execute the statement if the result of the expression is true.
- If the result of the expression is false, skip the statement.
2. "If-else"
a. Format:

b. Steps of Judge the result of the expression:
- Judge the result of the expression
- If the result of the expression is true, execute statement 1
- If the result of the expression is false, execute statement 2
3. Using multi-branch if statement to realize multi-branch processing
a. The grammatical format of the multi-branch if statement:

b. The execution steps of the multi-branch if statement:
- The result of expression 1 is judged.
- If the result of expression 1 is true, statement 1 is executed; otherwise expression 2 is judged.
- If the result of expression 2 is true, statement 2 is executed; otherwise statement 3 is executed.
C. "Switch"
1. Format:

2. The execution steps of the switch statement:
- Calculate the value of the expression after switch
- Comparing the calculated results from top to bottom with the constant values after case
- If equal, the code block after the constant is executed and the break statement ends.
- If the constants after any case do not match, execute the statement in default
NOTE:
01. If you need to jump out after each case is executed, don't forget to write a break after each case.
02. Constants after case cannot be the same
03. The order of default blocks can be changed, but attention should be paid to their execution order. Normally, default blocks are placed at the end, or they can be omitted.
本文深入探讨了Java中的流程控制结构,包括顺序结构、选择结构和循环结构的使用方法及语法格式。详细介绍了单分支、双分支和多分支选择结构,并讲解了switch语句的执行步骤,帮助读者掌握Java编程的基础。
8188

被折叠的 条评论
为什么被折叠?



