Process Control based on Java syntax

Source: Internet
Author: User

When designing a program, we often make logical judgments, do different things according to different results, or do something over and over again, and we call it process control for a job like this. In Java, Process control is divided into two main categories: selection and looping. These two classes are described in turn.

First, select

The selection control is divided into two kinds: if...else ... and switch

1, If...else ..., this control in the performance is divided into: single-branch structure, dual-branch structure and multi-branch structure

1) Single Branch

Single branch structure. This is the simplest of a selection structure, it is simply to determine whether a condition is true, if it is set up to execute a piece of code, the statement form is:

if (expression) {

......

}

2) Dual Branch

This is a standard, complete if statement implementation form, it first determine whether a condition is true, if it is established to execute a piece of code, if the condition is not true, execute another piece of code, the statement form is:

if (expression) {

......

}else{

......

}

3) Multi-branch This is one of the nested forms of the IF statement, which is a nesting of multiple if statements, in the form of the following statements:

if (expression) {

......

}else if (expression) {

......

}else{

......

}

2. Switch

The switch statement is dedicated to implementing a multi-branch structure program, which is characterized by a clear and intuitive branch. The parentheses after the switch statement can be any expression, with its integer part compared to each constant expression. Where the constant expression must be able to be automatically converted to an integer type, such as a character type, a short integer, an enumeration, and so on (JDK7 starts supporting strings). The statement form is as follows:

switch (expression) {

case constant Expression 1: statement 1

Case constant Expression 2: statement 2

......

case constant Expression N: statement n

Default: Statement n+1

}

Ii. circulation (to be continued)

1. For

2. While

3, Do...while

4. foreach

This article is from the "Jianggujin blog" blog, make sure to keep this source http://jianggujin.blog.51cto.com/6808292/1719839

Process Control based on Java syntax

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.