Control Execution Process-continue, break, tag

Source: Internet
Author: User

Return
1. Return Value of the method (no void return value)
2. Exit the current method and return the value
Break
1. Control the cyclic process
2. The break forcibly exits the loop and does not execute the remaining statements in the loop.
Continue
1. Control the cyclic process
2. Stop the iteration of the current loop, return to the starting point of the loop, and start the next iteration.
Label followed by a colon identifier
Lable:
Continue and break usually only interrupt the current loop. If they are used with tags, the loop will be interrupted and reach the tag location:
Package com. JavaTest;
Public class LabledFor {
Public static void main (String [] args ){
Int I = 0;
Outer:
While (true ){
System. out. println ("outer while loop ");
While (true ){
I ++;
System. out. println ("I =" + I );
If (I = 1 ){
System. out. println ("continue ");
Continue;
}
If (I = 3 ){
System. out. println ("continue outer ");
Continue outer;
}
If (I = 5 ){
System. out. println ("break ");
Break;
}
If (I = 7 ){
System. out. println ("break outer ");
Break outer;
}
}
}
}
}
Program Execution output:
Outer while loop
I = 1
Continue
I = 2
I = 3
Continue outer
Outer while loop
I = 4
I = 5
Break
Outer while loop
I = 6
I = 7
Break outer
1) continue will return to the beginning (top) of the innermost loop and continue execution
2) The continue with tags will reach the tag location and re-enter the loop next to the tag.
3) The break is interrupted and jumps out of the current loop.
4) The labelled break will interrupt and jump out of the loop indicated by the tag.
The only reason for using tags is that a nested loop exists and you want to use break or continue from the nested
This article is from the "bit by bit on the IT Road" blog

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.