JAVA Process Control Selection statement

Source: Internet
Author: User

In programming, there are three basic techniques that can change the process control of a program:

    1. Call method;
    2. Select
    3. Cycle.

Here, we mainly talk about the choice statement.

The selection statements in Java are essentially the same as in C, including:

    1. If statement;
    2. If/else statement;
    3. Switch statement.

If statement:

1 if (Boolean expression) {2     // if the Boolean expression in parentheses after the If is true, the statement    here is executed 3 }

If/else statement:

1 if (Boolean expression) {2     // executes the statement here when the Boolean expression is true for the if post-parenthesis; 3 }else{4     // Executes the statement here when the Boolean expression is false in parentheses after the IF. 5 }

Or

if(Boolean expression) {//executes the statement here when the Boolean expression is true for the if post-parenthesis;}Else if(Boolean expression) {//executes the statement here when the Boolean expression is false in parentheses after this else if;}Else if(Boolean expression) {//executes the statement here when the Boolean expression is false in parentheses after this else if;}Else if(Boolean expression) {//......}Else{    //The above conditions are not satisfied when the implementation;}

Switch statement:

The switch statement allows the variable to be tested for equality with multiple values, and the switch statement generally has the following format:

1 Switch(variable) {2      Casevalue 1:3 statement;4          Break;//options available5      Casevalue 1:6 statement;7          Break;//options available8     .9     .Ten     . One     . A     . -     . -  CaseValue N: the statement; -          Break;//options available - default://default Optional - statement; +// Break;//options available -}


At this point, the three selection statements for Java Process Control are complete.

JAVA Process Control Selection statement

Related Article

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.