java popular control statement

Java if statement:

grammar:

 

Such as:

 

If ... else of Java conditional statement:

grammar:

Such as:

 

Multiple if conditional statements in Java:

grammar:

 

Such as:

 

Java conditional nested if:

grammar:

 

E.g:

 

 

Switch of Java conditional statement:

grammar:

Execution process: When the value of the expression after the switch is the same as the value after the case statement, the execution is started downward from this position until the end of the break statement or the switch statement block; if there is no matching case statement, the code of the default block is executed .

Such as:

Some small secrets I have to say:

1. The value of the expression in parentheses after the switch must be integer or character

2. The value behind the case can be a constant value, such as 1, 2; it can also be a constant expression, such as 2 + 2; but it cannot be a variable or an expression with a variable, such as a * 2

3. After the case is matched, the program code in the matching block is executed. If no break is encountered, the content of the next case block will continue to be executed until the end of the break statement or switch statement block.

 

operation result:

 

4. You can combine case statements with the same function, such as

5. The default block can appear in any position or can be omitted

 

Java loop statement while:

Three kinds of loops commonly used in Java: while, do ... while, for

 

grammar:

 

 

Features: judge first, then execute

Such as:

 

grammar:

 

Features: execute first, then judge

This shows that the do ... while statement ensures that the loop is executed at least once!

Such as:

 

 

grammar: 

For example, if you output 1000 times "I Love Lesson Network", the implementation code using for is:

 

Java loop jump statement break:

Implementation code:

 

Java loop jump statement continue:

The role of continue is to skip the remaining statements in the loop body and execute the next loop.

For example, to print all even numbers between 1--10, use the continue statement to implement the code as:

 

Multiple loops of Java loop statements:

The structure containing the loop statement in the loop body is called a multiple loop. The three kinds of loop statements can be nested on their own or within each other. The most common is the double loop. In the double loop, every time the outer loop is executed, the inner loop is executed once.

As follows:

Guess you like

Origin www.cnblogs.com/DonVin/p/12672368.html