break and continue labels
suggest changebreak and continue may be followed by a label. This is not goto. break label finishes the labeled statement and continues after it. continue label starts the next iteration of a labeled loop.
for (let i = 0; i < 5; i++) {
nextLoop2Iteration:
for (let j = 0; j < 5; j++) {
if (i == j) break nextLoop2Iteration;
console.log(i, j);
}
}
When i === j, break leaves the inner loop before console.log, so each outer pass prints j from 0 through i - 1. The i === 0 pass prints nothing.
1 0
2 0
2 1
3 0
3 1
3 2
4 0
4 1
4 2
4 3
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents