JAVA-control process, java Process

Source: Internet
Author: User

JAVA-control process, java Process

In Java, you must declare a public class of the main () method. The program starts execution from the first statement of the main () method, and then executes subsequent statements one by one until it reaches the end of the program-the end of the main () method. However, during program design, we often need to change the program control process, that is, the statement execution sequence. There are three basic technologies that can change the control process of a program:

1,Call Method. The caller will cause the control flow to exit the current method and transfer it to the called method. For example, when we call println (), the control program leaves main (), switches to println (), and returns the main () method when the execution is complete.

2,Select.Java has two options: if/else statements and switch statements. The three-object operator can also be used for selection, but it is usually only a short version of if/else.

3,Loop.Java has three types of loop statements: for Loop, while loop, and do/while loop.

 

For Jump statements break and continue:

The break keyword can be used in any loop control structure,So that the cycle ends immediately.

The continue keyword can be used in any soul control structure, which causesThe loop immediately jumps to the next iteration of the loop.

Note:In Java, excessive use of break and continue statements is not recommended. The two keywords appear in Java mainly because they are used by C and C ++. They have a certain purpose, especially the break keyword. However, in many cases, we can redesign the code to avoid using break and continue.

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.