Java control execution Process--thinking in Java learning

Source: Internet
Author: User


The common control execution flow has if-else; iterative while,do-while,for,foreach;return;break,continue;
tags used in conjunction with break,continue; switch; in the thinking in Java Chapter,
There are two places that have been re-recognized and shared with you.
1, return has two functions, 1. Sets the return value of a method; 2. Exits the current method.
So any method can use the return statement, and using return in the Void method is
Use return to exit the current method's role.
And there is no return statement in the method that returns void, at the end of the method there is an implicit
The return.
2, and break,continue with the use of the label to achieve the role of Goto.
1. The general continue will return to the beginning of the most inner loop (top) and continue execution.
2. The tagged continue will reach the position of the label and re-enter the loop immediately following the label.
3. A normal break breaks and jumps out of the loop that the label refers to.
4. A tagged break breaks and jumps out of the loop that the label refers to.

It is important to note that the only reason to use tags in Java is because there is a loop nesting, and you want to get from multiple layers of nesting
Break and continue.

Introduce code snippets from thinking in Java to learn about:

public class Labeldemo {public static void main (string[] args) {int i = 0;outer:for (; True;) {inner:for (; i <; i++) {System.out.println ("i =" + i), if (i = = 2) {System.out.println ("continue"); continue;} if (i = = 3) {System.out.println ("break"); i++;break;} if (i = = 7) {System.out.println ("continue outer"); i++;continue outer;} if (i = = 8) {System.out.println ("break outer"), Break outer;} for (int k = 0; k < 5; k++) {if (k = = 3) {System.out.println ("continue inner"); Continue inner;}}}}}

The label of the notation for the signature plus ":", in multiple nested loops, continue tagging, indicating the next loop to enter the tag followed by the loop (similar to the continue in a single-layer loop, the difference is the loop after the label); break tagging, Indicates a loop that follows a direct jump out of the label (like a break in a single-layer loop, the difference is the loop that follows the tag).

Java control execution Process--thinking in Java learning

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.