Search code examples
javascriptcontinuelabeled-statements

Why is this labeled javaScript continue not working?


I am using this code to weather some circles are overlapping:

iCantThinkOfAGoodLabelName:
x = genX(radius);
y = genY(radius);
for(i in circles) {
  var thisCircle = circles[i];
  if(Math.abs(x-thisCircle["x"])+Math.abs(y-thisCircle["y"])>radius*2) { //No overlap
    continue;
  } else { //Overlap
    continue iCantThinkOfAGoodLabelName; //<- Line 256
  }
  thisCircle = [];
}

But when the continue statement is reached, chrome's developer console gives me this: client.html:256 Uncaught SyntaxError: Undefined label 'iCantThinkOfAGoodLabelName'


Solution

  • The label should come immediately before the loop

    x = genX(radius);
    y = genY(radius);
    
    iCantThinkOfAGoodLabelName:
    for(i in circles) {