Java Basic Learning Notes--6 (branch statement)

Source: Internet
Author: User

Branch statements

1) If...else ... Branch

① alone if statement, not in conjunction with else

Syntax: if (Boolean expression) {

statement block;

}

The following code ...

Operation: When the Boolean expression is set, the statement block is executed, and the statement block is skipped to execute the later content.

Case 11:

650) this.width=650; "title=" 11.png "src=" Http://s3.51cto.com/wyfs02/M02/6C/D8/wKioL1VUG3Lhh-M1AAH-sqBdP W0596.jpg "width=" 606 "height=" 413 "alt=" wkiol1vug3lhh-m1aah-sqbdpw0596.jpg "/>

②if...else ... Statement

Syntax: if (Boolean expression) {

Statement Block 1;

} else {

Statement Block 2;

}

Follow-up code ...

Operation: When the Boolean expression is established, the contents of the statement block 1 are executed, the contents of the statement Block 2 are not established, and (both are selected).

Continue with subsequent code after execution.

Case 12:

650) this.width=650; "style=" width:613px;height:464px; "title=" 12.png "src=" http://s3.51cto.com/wyfs02/M0 2/6c/dd/wkiom1vugnoggoi8aak97uude5a956.jpg "width=" 628 "height=" 460 "alt=" wkiom1vugnoggoi8aak97uude5a956.jpg "/ >

Results:

650) this.width=650; "title=" 121.png "src=" Http://s3.51cto.com/wyfs02/M01/6C/DD/wKiom1VUGq7BEPVXAABal6SQ J_u766.jpg "alt=" Wkiom1vugq7bepvxaabal6sqj_u766.jpg "/>

650) this.width=650; "title=" 122.png "src=" HTTP://S3.51CTO.COM/WYFS02/M02/6C/D8/WKIOL1VUHDFCX7LOAABYPRCM Lcc362.jpg "alt=" Wkiol1vuhdfcx7loaabyprcmlcc362.jpg "/>

Case 13:

650) this.width=650; "title=" 13.png "src=" Http://s3.51cto.com/wyfs02/M02/6C/D8/wKioL1VUHJzCZKvEAAIzpUieT 2q004.jpg "Width=" 619 "height=" 436 "alt=" wkiol1vuhjzczkveaaizpuiet2q004.jpg "/>

③if. else if ... else if ... else ... Multi-Conditional branching statements

Syntax: if (Boolean expression 1) {

Statement Block 1

} else if (Boolean expression 2) {

Statement Block 2

} else if (Boolean expression 3) {

Statement Block 3

} else {

Statement Block 4

}

Operation: From the top down, which if after the Boolean expression is formed, then the execution of which after the statement block is not true,

Finally executes the block of statements inside the else. (All branches will end up with only one execution)

Case 14:

650) this.width=650; "title=" 14.png "src=" http://s3.51cto.com/wyfs02/M00/6C/D8/wKioL1VUHOWwRE_FAAKVT7mI7 Ek892.jpg "width=" 624 "height=" 513 "alt=" wkiol1vuhowwre_faakvt7mi7ek892.jpg "/>

2) Switch...case ... Branch

Switch-case is a special branch structure;

Switch-case can be executed from different program portals, depending on the value of an integer value.

Grammar:

switch (int-expression) {

Case integer constant value 1: statement 1; break;

Case integer constant Value 2: statement 2; break;

... ...

Default: statement n;

}

Arithmetic: Evaluates the value of an integer expression first,

If the value equals the integer constant value 1, then statement 1 is executed, and then break exits the branch.

If the value equals the integer constant value 2, then statement 2 is executed, and then break exits the branch.

If no matching value is found, only statement n is executed. Then exit the branch.

Note: If there is no write break behind each branch, then when the branch is entered, it is executed until the default and then exits.

The type that can be placed after switch (): int, char, short, Byte, String (JDK1.7);

Case 15:

650) this.width=650; "style=" width:657px;height:354px; "title=" 15.png "src=" http://s3.51cto.com/wyfs02/M0 1/6c/dd/wkiom1vug6jwbp-1aandbkpa5v8015.jpg "width=" 911 "height=" 495 "alt=" wkiom1vug6jwbp-1aandbkpa5v8015.jpg "/ >

Case 16:

650) this.width=650; "style=" WIDTH:675PX;HEIGHT:539PX; "title=" 16.png "src=" http://s3.51cto.com/wyfs02/M0 2/6c/dd/wkiom1vug9-y437saakehr-nyam522.jpg "width=" 715 "height=" 567 "alt=" wkiom1vug9-y437saakehr-nyam522.jpg "/ >

This article is from "Forever Young" blog, please be sure to keep this source http://kingkongzhao.blog.51cto.com/6319491/1651210

Java Basic Learning Note-6 (branch statement)

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.