Goto,continue,break in Java

Source: Internet
Author: User

Goto: Goto is still a reserved word in Java, but it is not used in the language, and Java has no goto.

Definition of reserved words:

Reserved words (reserved word), which are words that have already been defined in a high-level language, can no longer be used by users as variable names or procedure names.
Reserved words include keywords and unused reserved words. Keywords are those words that have a specific meaning in the language and become part of the grammar. In some languages, some reserved words may not be applied to the current syntax, which is the difference between a reserved word and a keyword. In general, this may be due to scalability considerations. For example, JavaScript has some future reserved words, such as abstract, double, Goto, and so on.
Each programming language has its own set of reserved words.

Java uses continue and break to perform some similar jumps.

But continue and break are not a jump, but a way to interrupt an iterative statement.

outer-iteration {
inter-iteration {
        Break Interrupts internal iterations, back to external iterations
 
  
        Continue Move the execution point back to the beginning of the internal iteration

}
}

After the continue and break are tagged:

Outlabel:
outer-iteration {
    Inlabel:
inter-iteration {
        Break Inlabel; Interrupts the inner iteration (inter-iteration referred to by Inlabel), back to the outer iteration, here with break; equivalence
 
  
        Break outlable; Interrupts both internal and external iterations, and does not re-enter iterations
 
  
        Continue Inlabel; Moves the execution point back to the beginning of the inner iteration (inter-iteration referred to by Inlabel), here and continue; equivalence
 
  
        Continue Outlabel; Moves the execution point to the beginning of the outer iteration (the outer-iteration referred to by Outlabel)

}
}

In Java, a label can only work if it pail into any statement before the iteration statement and between the iteration statement.

The only reason to use tags in Java is because of the existence of nested loops, and to break and continue from multiple layers of nesting.

Goto,continue,break in Java

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.