Java Fundamentals (3) Conditional statements

Source: Internet
Author: User

1. Simple if statement

If, else belongs to the conditional branch

if (condition) {

EXECUTE statement

}else{

EXECUTE statement

}

Points:

Program Flow

Sequential execution

Select Execute

Loop execution

Conditional branching statements are used to select the execution

2. Multiple if, Else statements

Grammar

if (condition 1) {

This block of code is executed when the condition is met 1 o'clock

}else if (condition 2) {

This block of code is executed when the condition is met 2 o'clock

}else if (condition 3) {

This block of code is executed when the condition is met 3 o'clock

}else{

Performed when the above 3 conditions are not met

}

Important: Else always belongs to the most recent if that does not correspond to else

3.switch, Case statement

Grammar

Switch (value) {

CASE constant 1:

Statement 1;

Break

Case constant 2:

Statement 2;

Break

Case Constant 3:

Statement 3;

Break

Default

Statement 3;

}

Points:

Value is not a long, can be integer, character type

Break statements must be added to prevent leaks;

default is optional;

The result of an expression is a fixed value instead of a range

Java Fundamentals (3) Conditional statements

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.