Home  >  Article  >  Java  >  How to use Java double loop break

How to use Java double loop break

高洛峰
高洛峰Original
2016-11-21 11:43:471575browse

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.


Statement:
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