Home >Java >javaTutorial >control statements in java

control statements in java

高洛峰
高洛峰Original
2016-11-15 15:18:261102browse

Control statement

1.1 Sequential structure (the most common)

Features: The code is executed sequentially from top to bottom

1.2 Selection structure:

if Judgment statement:

switch Judgment statement:

Precautions for using the Switch statement :

1. There needs to be a break after each statement to prevent switch penetration.

2. The variables used for judgment in the switch statement can only be int, short, char, byte String (only available after jdk7)

3. The data following Case must be constant.

Advantages of switch statement: clear statement structure and fast running speed.

Disadvantages of the switch statement:

The switch that can be done by If may not be able to be done, and the if that can be done by switch can definitely be implemented.

1.3 Loop structure

While loop: first judge and execute

structure:

while (loop condition) {

loop body.

}

do while loop: execute first and then judge, the loop body will definitely be executed once.

Structure:

do{

loop body;

}while (loop condition);

for loop:

Structure:

for(;;){

Loop body

}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn