Loop Control: break, continue and labels
break leaves a loop and continue skips to the next round. Labels let you exit nested loops. Avoid infinite loops by changing the condition.
Example
outer: for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (j === 1) continue;
if (i === 2) break outer;
console.log(i, j);
}
}Exercise
Skip this round.
;Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.