Java programs control the execution flow of methods through control statements to achieve specific functions
There are three main process control structures in Java
Sequential structure
Selection structure
Loop structure.
The combination of the three structures can solve any complex problem.
Branch statements are also called conditional statements
Conditional statements allow part of the program to be selectively executed based on the value of certain expression.
JavaProgramming language supports dual-way if and multi-way switch branch statements.
else Statement
In the Java programming language if () uses a Boolean expression instead of a numeric value .The form is as followsif(Boolean type expression 1){ Statement 1;}The following code can Write according to the actual situation else if (expression 2) { Statement 2;## Statement 3;
#} else{ Statement n;} ##Switch statement
The value of the expression must be compatible with an integer or an enumeration typeConstant
The value includes byte, short, int and char and cannot be astring
orObject
also cannot be a long valueswitch statement syntax format
switch(integer or character type
statement1; break; break; ## Break here means jumping out of this branch.
If there is no break statement as the end sentence of a certain case code segment, the execution of the program will continue to the next case without checking the value of the case expression.
When the value of a variable or expression cannot match any case value, the optional default character (default) indicates the program code case that should be executed; it can be followed by a direct constant value.
Loop structure The main loops used in java arefor loopwhilewhile
and do while. Not much but you still need to remember the following three forms of loop statements for loop for (initialization statement; loop condition; incremental expression){ Loop body ) }# The running program will output a hundred times "Hello World"
# 接 Next we will write a whiledo ## stereotyped with the same function. #while loop
while(loop condition){
Execution statement
----
}
Conditional judgment determines whether to execute the execution statement within the curly brackets.
##
The syntax format of the statement is # } while loop condition
Syntax Description In the do-while statement, the loop body part is the code part that is repeatedly executed. The loop condition refers to the condition for the loop to be established. The loop condition is a boolean type. When the value is true, the loop is executed, otherwise the loop ends and the entire statement ends with a semicolon. Execution process When the do-while statement is executed, the loop body is first executed and then the loop condition is judged. If the loop condition is not established, the loop ends. If the loop condition is established, the loop body continues to be executed. After the loop body is executed, the loop condition is judged in sequence. analogy.The above is the detailed content of Detailed explanation of process control in java. For more information, please follow other related articles on the PHP Chinese website!