Selection structure in Week_02_Java

Selection structure in Java

Through this week's course study, I learned what is the selection structure and various types of selection structure. The following is a review of the various selection structures I have learned.

1. If selection structure (the most basic structure)

When the program is executed, the conditions are judged first. When the result is true, the program first executes the code block in the if braces, and then executes the following code. When the result is false, the code block in the if braces is not executed, but the code behind the if structure is executed.

Second, if-else selection structure

Compared with the basic selection structure of if, if-else can be better than if, if not, it will not cause code redundancy and save time.

Three, multiple if selection structure

When multiple if selection structures are used, the judgment conditions cannot be disordered, and the order of program execution is from top to bottom. When the first meets the conditions, the corresponding code block will be executed, and no other code blocks will be executed. Judgment execution.

Four, nested if selection structure

In the nested if selection structure, only when the conditions of the outer if selection structure are met, the condition of the inner if selection will be judged. Else is always paired with the if that lacks else in front of it. In addition, when judging the value of the String type, use equals to judge.

Five, switch selection structure

Compared with if selection structure, switch selection structure is generally used in equivalence judgment, while if selection structure is used in interval judgment.

Guess you like

Origin www.cnblogs.com/txp497131445/p/12735210.html