In Java, goto, continue, break, and gotocontinue

Source: Internet
Author: User

In Java, goto, continue, break, and gotocontinue

Goto: in Java, goto is still a reserved word, but it is not used in the language; Java does not have goto.

   

Definition of reserved words:

Reserved word refers to words that have been defined in advanced languages. You cannot use these words as variable names or process names.
Reserved Words include keywords and unused reserved words. Keywords refer to words that have specific meanings in the language and become part of the syntax. In some languages, some reserved words may not be applied to the current syntax, which makes the difference between reserved words and keywords. In general, this situation may be caused by considering scalability. For example, Javascript has some reserved words in the future, such as abstract, double, and goto.
Each programming language defines its own set of reserved words.

Java uses continue and break to perform similar jump operations.

However, continue and break are not a jump, but a method to interrupt iteration statements.

 

   
outer-iteration {
inter-iteration {
Break; // interrupt internal iteration and return to external Iteration
 
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; // interrupt internal iteration (inter-iteration referred to by inLabel), return to external iteration, which is equivalent to break;
 
Break outLable; // interrupt both the internal and external iterations and do not re-enter the iteration.
 
Continue inLabel; // make the execution point move back to the start point of the inter-iteration defined by inLabel, which is equivalent to continue;
 
Continue outLabel; // move the execution point to the start point of the external iteration (outer-iteration referred to by outLabel ).

}
}

In Java,TagIt takes effect only when no statement is placed with the iteration statement before the iteration statement.

In JavaThe only reason for using tagsIt is because of the existence of loop nesting and the desire to break and continue from multi-layer nesting.

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.