Java Process Control---personal reference

Source: Internet
Author: User

Tag: The back does not perform the other two version types of sys selection

Preface: I write the purpose of the blog is very simple, very pure, I usually learn things, put on the blog, free time, you can see what they have seen.

Java Process Control Statements: Judging structure, selecting structure, looping structure

A Judging structure

The judging structure includes the If branch, the If...else ... Branch, If. Else If...else Branch, if nested four kinds.

1, if (conditional expression) {

Execute the statement;

}

2, if (conditional expression) {

Execute the statement;

}

else{

Execute the statement;

}

3, if (conditional expression 1) {

EXECUTE statement

}

else if (conditional expression 2) {

Execute the statement;

}

else{

Execute the statement;

}

4, if (conditional expression 1) {

if (conditional expression 2) {

EXECUTE statement

}

else{

Execute the statement;

}

}

else{

Execute the statement;

}

1. If Branch statement


"Example 1":

int x = 5;

if (x = = 5) {

/* when "x = = 5" is established, the statement is executed, and conversely, the statement block in "{}" is skipped, and the other code is executed directly later.

SYSTEM.OUT.PRINTLN ("condition established, the statement executed successfully");}

2. If-else Branch Statements


"Example 1":

if (x = = 5) {

When "X==5" is established, execute the statement

SYSTEM.OUT.PRINTLN ("condition established, the statement executed successfully");

}

else{

Executes the statement when the condition is not true

SYSTEM.OUT.PRINTLN ("The condition is not valid, the statement does not execute");

}

3. If-elseif-else Branch Statements


"Instance 1"

if (x > 5)

System.out.println ("X> 5 established, execute the statement");

else if (x < 5)

System.out.println ("x< 5 established, execute the statement");

Else

System.out.println ("Execute the statement when the preceding conditions are not true");

4. If nested branch statements


"Example 1":

int m = 6;

if (x < 10) {

if (m = = 6) {

System.out.println ("When x < 10 and M = = 6 o'clock Executes the statement");

}else{

System.out.println ("When x < 10 and M! = 6 o'clock Executes the statement");

}

}else{

System.out.println ("When x < 10 fails to execute the statement immediately");

}

Two Select structure

"Note" JDK1.7 versions of the switch expression support string type

When you use switch to select a structure,

1. The result of conditional expression can only be byte, int, short, char

2. Case and default are not written in order, and when there is no match, execute the default

4. There are two ways to end a switch statement: encounter a break or execute to the end of a switch statement

3, case or default after the break is can be omitted, when if the match is not a corresponding or default, the program will continue to execute down until the program encounters a break or the end

three . Loop Structure

The judging structure includes the while statement, the Do-while statement, the FOR statement

1, while (conditional expression) {

Circulation body;

}

2, do{

Circulation body;

}while (conditional expression);

3, for (expression 1; conditional expression; expression 2) {

Loop body

}

The "note" while and do while are distinguished, while the while is executed first, while the do is executed before judgment, that is, the loop body executes once, regardless of whether the condition is true or not, when the do is used.

"Note" Break is to jump out of the loop to continue the execution of the content behind the loop, if the multi-layer loop can only jump out of the layer loop; Continue end this loop and execute the next loop directly

Java Process Control---personal reference

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.