java--Control Process

Source: Internet
Author: User

In Java, you declare a common class that lends the main () method. The program executes from the first statement of the main () method, followed by a subsequent statement, until it reaches the end of the-main () method at the end of the program. However, in programming, we often need to change the program control process, that is, the order of execution of statements. There are three basic techniques that can change the program's control flow:

1. Call method . The caller will cause the control flow to move away from the current method to the method being called. For example, when we call println (), the control program leaves main (), goes to println (), and returns to the main () method when execution is complete.

2, choose. there are two mechanisms for making choices in Java: The If/else statement and the switch statement. The trinocular operator can also be used for selection, but it is usually a shorthand version of If/else.

3, cycle. There are three looping statements in Java: For loop, while loop, Do/while loop.

For jump statements break and continue:

The break keyword can be used in any loop control structure, allowing the loop to terminate immediately.

The Continue keyword can be used in any soul-control structure, which causes the loop to jump immediately to the next iteration of the loop.

  Note: in the Java language, excessive use of break and continue statements is not advocated. These two keywords appear in Java mainly because they are used in C and C + +. They have a certain purpose, especially the break keyword. However, in many cases, we can avoid using break and continue by re-designing the code.

java--Control Process

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.