Java programs use Control statements to control the execution of a method to implement specific functions
There are three main types of process control structures in Java
Sequential structure
Select structure
Loop structure.
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8E/8A/wKiom1jD66jBfSxSAAjbyK0IlJU975.jpg-wh_500x0-wm_ 3-wmp_4-s_1970826963.jpg "title=" 2017_03_11_20_25.11.jpg "alt=" Wkiom1jd66jbfsxsaajbyk0ilju975.jpg-wh_50 "/>
The combination of three structures can be used to solve any complex problem.
A branch statement is also called a conditional statement
Conditional statements enable some programs to be selectively executed based on the values of certain expressions.
The Java programming language supports two-way if and multi-switch branch statements.
If-else statements
In the Java programming language, if () uses a Boolean expression instead of a numeric value.
form as follows
If (boolean-type expression 1) {
Statement 1;
}
The following code can be written according to the actual situation
else if (expression 2) {
Statement 2;
}
else if (expression 3) {
Statement 3;
}
...... ......
else if (expression N) {
Statement N;
}
else{
Statement N;
}
Switch statement
The value of an expression must be compatible with an integer or a constant value of an Enum enumeration type that contains a value of byte, short, int, and char that cannot be a string or an object and cannot be a long type
Switch statement syntax format
Switch (integer or character variable) {
Case CONST1:
Statement1;
Break
Case CONST2:
Statement2;
Break
.......
[Default:
Statement default;
break;]
}
Break here means to jump out of this branch.
If there is no break statement as the end sentence of a case code snippet, the execution of the program continues to the next one without checking the value of the case expression.
When the value of a variable or expression cannot match any case value, the optional default (default) indicates that the program code that should be executed can be a direct constant value.
Loop structure
Java primarily uses loops for the For loop while and does while not much used but still needs to remember the form of no three loop statements
For loop
for (initialization statement; loop condition; increment expression) {
Circulation body;
}
Example forint i = 0;i<100;i++{
System.out.println ("Hello World");
}
Running the program will output 100 "Hello World"
Next we will write a whiledo while loop with the same function
while (loop condition) {
EXECUTE statement
----
}
Determines whether execution statements within curly braces are executed based on conditional judgment.
The execution process first judges the loop condition when executing the while statement if the loop condition is false and executes the code followed by the while statement if the loop condition is true then the loop body code is executed and then the loop condition is determined until the loop condition is not established.
The syntax format for the Do-while statement is
do{
Loop Body
}while Cycle Conditions
The syntax description in the Do-while statement that the loop body part is a repeating code part of the loop condition refers to the condition that the loop is formed, that the loop condition is a Boolean value of True when the loop executes otherwise the end of the loop ends with a semicolon.
Execution process when executing to the Do-while statement, the loop body is executed first and then the loop condition is determined if the loop condition is not established then the loop ends if the loop condition is true and then the loop body loop body execution is completed and then the loop condition is judged and then so on.
Process Control in Java