Java Program Flow Control

Source: Internet
Author: User

Control processes are the foundation of all programming languages, and Java is no exception, including selection and looping.

⑴. SELECT statement: ①if statement: An If statement consists of a Boolean expression group followed by one or more statements.

Syntax form: if (Boolean expression) {

Expression is true, the statement executed is

}

②if......else: An If statement can be followed by an optional else statement for the Boolean expression false when executed.

Statement form: if (Boolean expression) {

Executes when the expression is true

}else{

Execute when Boolean expression is False

}

Note: Else can contain another if statement.

The ③switch:switch statement allows a variable to be tested for equality with multiple values, and each value is invoked and instrumented by a case statement.

Statement form: SWICTH (variable) {

Case Value:

Statement

Break

Default

Statement

}

Note: Case can be multiple.

⑵ Loop statement: While Loop, Do......while Loop, for loop.

①while Loop: A control structure that allows for repeated execution.

Statement form: while (loop condition) {

Loop body

}

Note: While easy to become a dead loop.

②do......while Loop: The Do......while loop is similar to the while loop, unlike a do......while loop that executes at least once.

Statement form: do{

Loop body

}while (cyclic conditions);

③for Loop: A For loop is a control structure that allows you to write a loop that executes a specified number of times.

Statement form: for (initial value; cycle condition; self-increment + + or auto-subtract-) {

Loop body

}

Break statement: Terminating execution of a loop

Continue statement: The next iteration of the loop that causes the loop to jump.

  

Java Program Flow Control

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.