Home > Java > javaTutorial > body text

How to use Java double loop break

高洛峰
Release: 2016-11-21 11:43:47
Original
1591 people have browsed it

break only breaks out of the current loop, which is the inner loop. If you want to break out of the outer loop, there are two ways:
1: for(int i = 0;i<9;i++){ //Use two breaks
for(int j = 0;j<8;j++){
break;
}
break;
}
2: flag: for(int i = 0;i<9;i++){ //Add a mark before the loop to be jumped out, Then you can use break flag at any
//any position in the marked loop; you can jump out of the marked loop
for(int j = 0;j<8;j++){
break flag;
}
}

Break jumps out of the current layer loop, which means that the inner loop of this layer ends and the outer loop continues to be executed; the scope of break is to jump out of the current layer and execute the previous layer loop.
Explanation: break means to jump out of this loop and continue to execute the previous layer, that is, the outer layer. Contiue means to jump out of this loop and continue to execute the inner loop.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template