Taking control of loops
Searching your bag for keys, you stop as soon as you find them. Sorting rice, you skip the stones. And a chessboard is rows *of* squares — a loop inside a loop. Today: break, continue and nested loops.
break and continue
for (let i = 1; i <= 10; i++) {
if (i === 4) {
break;
}
console.log(i);
}
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue;
}
console.log("Room " + i);
}break = "I'm done with this loop." continue = "skip this one, carry on."