There are three types of process control structures in the Java language:
1. Sequential structure
2. Select structure
3. Cyclic structure
Sequential structure
Meaning: Executes sequentially in order of the statement.
Select structure
Meaning: Select one of the multiple branches according to the criteria to execute. For example: If statement, IF-ELSE statement, switch statement.
Conditional statements (if, if-else, if nesting, multiple if):
Features: Accurate detection of the condition is established or not. Then decide whether to execute the following statement.
If statement
Format:
if (conditional expression)
{
Statement
}
If-else statements
Format:
if (conditional expression) {
Statement 1
}
else{
Statement 2
}
If nesting
Format:
if (conditional expression 1) {
if (conditional expression 2) {
Statement 1
}
else{
Statement 2
}
}
else{
Statement 3
}
Multiple if
Format
if (conditional expression 1) {
Statement 1
}
else if (conditional expression 2) {
Statement 2
}
else if (conditional expression 3) {
Statement 3
}
...
else{
Statement n
}
Note: If the IF statement has only one condition, you can omit the left and right brackets.
Multi-SELECT statement (switch statement)
Features: You can make multiple selections a simplification.
Format:
Switch (expression 1)
{
Case value 1:
Statement 1;
Break
Case Value 2:
Statement 2;
Break
Default
Statement 3;
}
Note: If none of the case matches, the default statement is executed. Break is the meaning of the jump statement.
Loop structure
For example, a while statement, a do-while statement, a for statement.
While loop
Format:
while (conditional expression)
{
Circulation body;
}
Do-while Cycle:
Format:
do{
Circulation body;
}while (conditional expression);
Note: The loop body of the Do-while loop is executed at least once.
For loop (Assignment initial value; judging condition; assignment increment and decrement)
{
Circulation body;
}
Control transfer Statements
Return statement:
Defined in the method, there are 2 functions: 1, the return method specifies the value of the type (this value is always determined), 2, the execution of the End method (only a return statement).
Format:
return expression;
Note: The type of the expression is the same as the return value type of the method.
The return statement is used in methods that return a value type other than void, not only to return a base type, but also to return an object (including a user-defined class).
Break statement:
Function: The process of the program is transferred from the inside of a block of statements.
Function: Jump out of the loop where it is and continue execution from the subsequent statement of the loop.
Continue statement:
Function: Skips the remaining statement of this round loop and resumes execution at the beginning of the loop. Can only be used in the loop structure.
Process Control in the Java language