Control processes are the foundation of all programming languages, and Java is no exception, including selection and looping.
⑴. SELECT statement: ①if statement: An If statement consists of a Boolean expression group followed by one or more statements.
Syntax form: if (Boolean expression) {
Expression is true, the statement executed is
}
②if......else: An If statement can be followed by an optional else statement for the Boolean expression false when executed.
Statement form: if (Boolean expression) {
Executes when the expression is true
}else{
Execute when Boolean expression is False
}
Note: Else can contain another if statement.
The ③switch:switch statement allows a variable to be tested for equality with multiple values, and each value is invoked and instrumented by a case statement.
Statement form: SWICTH (variable) {
Case Value:
Statement
Break
Default
Statement
}
Note: Case can be multiple.
⑵ Loop statement: While Loop, Do......while Loop, for loop.
①while Loop: A control structure that allows for repeated execution.
Statement form: while (loop condition) {
Loop body
}
Note: While easy to become a dead loop.
②do......while Loop: The Do......while loop is similar to the while loop, unlike a do......while loop that executes at least once.
Statement form: do{
Loop body
}while (cyclic conditions);
③for Loop: A For loop is a control structure that allows you to write a loop that executes a specified number of times.
Statement form: for (initial value; cycle condition; self-increment + + or auto-subtract-) {
Loop body
}
Break statement: Terminating execution of a loop
Continue statement: The next iteration of the loop that causes the loop to jump.
Java Program Flow Control