Why is this labeled javaScript continue not working?

JJJollyjim picture JJJollyjim · Jun 18, 2011 · Viewed 8.8k times · Source

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'

Answer

Brad Mace picture Brad Mace · Jun 18, 2011

The label should come immediately before the loop

x = genX(radius);
y = genY(radius);

iCantThinkOfAGoodLabelName:
for(i in circles) {