1122 if (imageData[((gy * g + y) * ngx * g +
1123 (gx * g + x)) * 4 + i] !== bgPixel[i]) {
1124 grid[gx][gy] = false
1125 break singleGridLoop1126 }
1127 }
1128 }
1114 while (gy--) {
1115 y = g
1116 /* eslint no-labels: ["error", { "allowLoop": true }] */
1117 singleGridLoop: while (y--) {1118 x = g1119 while (x--) {1120 i = 41121 while (i--) {1122 if (imageData[((gy * g + y) * ngx * g +1123 (gx * g + x)) * 4 + i] !== bgPixel[i]) {1124 grid[gx][gy] = false1125 break singleGridLoop1126 }1127 }1128 }1129 }1130 if (grid[gx][gy] !== false) {
1131 grid[gx][gy] = true
1132 }
683 fctx.fillStyle = 'rgba(255, 0, 0, 0.5)'
684 fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5)
685 }
686 break singleGridLoop 687 }
688 }
689 }
659 while (gy--) {
660 y = g
661 /* eslint no-labels: ["error", { "allowLoop": true }] */
662 singleGridLoop: while (y--) { 663 x = g 664 while (x--) { 665 if (imageData[((gy * g + y) * width + 666 (gx * g + x)) * 4 + 3]) { 667 occupied.push([gx, gy]) 668 669 if (gx < bounds[3]) { 670 bounds[3] = gx 671 } 672 if (gx > bounds[1]) { 673 bounds[1] = gx 674 } 675 if (gy < bounds[0]) { 676 bounds[0] = gy 677 } 678 if (gy > bounds[2]) { 679 bounds[2] = gy 680 } 681 682 if (debug) { 683 fctx.fillStyle = 'rgba(255, 0, 0, 0.5)' 684 fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5) 685 } 686 break singleGridLoop 687 } 688 } 689 } 690 if (debug) {
691 fctx.fillStyle = 'rgba(0, 0, 255, 0.5)'
692 fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5)
Labeled statements in JavaScript are used in conjunction with break
and continue
to control flow around multiple loops. For example:
outer:
while (cond()) {
while (cond2()) {
break outer;
}
}
While convenient in some cases, labels tend to be used only rarely and are frowned upon by some as a remedial form of flow control that is more error prone and harder to understand.
label:
while(cond()) { /* ... */ }
label:
while(foo) {
break label;
}
label:
while(bar) {
continue label;
}
label:
switch (a) {
case 0:
break label;
}
label:
{
break label;
}
label:
if (a) {
break label;
}
const x = {
label: "foo"
};
while (true) {
// code
break;
}
while (true) {
// code
continue;
}