在for…in循环中重置迭代器
这是我用来绘制一些随机圆的代码的一部分:
if(circles.length != 0) { //1+ circles have already been drawn
x = genX(radius);
y = genY(radius);
var i = 0;
iCantThinkOfAGoodLabelName:
for(i in circles) {
var thisCircle = circles[i];
if(Math.abs(x-thisCircle[\"x\"])+Math.abs(y-thisCircle[\"y\"])>radius*2) {
//overlaps
} else {
//overlaps
x = genX(radius);
y = genY(radius);
continue iCantThinkOfAGoodLabelName;
}
if(i == circles.length - 1) { //Last iteration
//Draw circle, add to array
}
}
}
问题在于,当存在重叠时,不检查具有新生成的坐标的圆是否与已经检查了重叠圆的圆重叠。我已经尝试过在使用continue语句之前将i设置为0,但这没有用。请帮助,我真的很困惑。
没有找到相关结果
已邀请:
3 个回复
悍蕾驮苇袜
。 请改用
。然后您可以通过设定
来重设。
橙绥
览幕堤分
的迭代。您需要去6英镑。