Java Control statements

Source: Internet
Author: User

Java Control statements
Control Statement 1.1 Sequence Structure (most common)

Feature: code execution from top to bottom

1.2 select structure:

If judgment statement:

Switch judgment statement:

Note:

1. After each statement ends, a break is required to prevent switch penetration.

2. The switch statement can only be used to determine the amount of variable int, short, char, byte String (available only after JDK 7)

3. The data following Case must be constants.

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

Disadvantages of the switch statement:

The switch that can be implemented by If is not necessarily feasible, and the switch can be implemented by if.

1.3 Loop Structure

While loop: first judge the execution

Structure:

While (loop condition ){

Loop body.

}

Do while loop: Execute first and then judge. The loop body will certainly execute once.

Structure:

Do {

Loop body;

} While (Cyclic condition );

For Loop:

Structure:

For (;;){

Loop body

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.