loop1: for (let i = 0; i < 4; i++) {
loop2: for (let j = 0; j < 3; j++) {
console.log('before')
if (i === 1) {
// when i equal to 1, jump out the loop2 immediately
continue loop1
// or can do break loop1
}
console.log(`i=${i}, j=${j}`)
}
}
foo: {
console.log('face');
break foo;
console.log('this will not be executed');
}
console.log('swap');
// this will log:
// "face"
// "swap"
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter