Actionscript 3 OOP无法使用if语句生成预期结果,并且>;标志
下面是我的代码: 当与给定节点一起提供时,此代码用于查找周围的节点 i、 eActionscript 3 OOP无法使用if语句生成预期结果,并且>;标志,actionscript-3,oop,Actionscript 3,Oop,下面是我的代码: 当与给定节点一起提供时,此代码用于查找周围的节点 i、 e for(变量i:uint=0;i
for(变量i:uint=0;inode.row+1)继续;
如果(test_node.columnnode.column+1)继续;
周围的\u节点。推送(测试\u节点)
}
/*
节点包含一个对象数组。
节点是我想用作测试变量的对象。
属性行包含对象所在的行
proerty列包含对象所在的克隆
*/
我得到了正确的结果(因为我正在学习教程),尽管我不知道为什么
这就是我的想法
因此,周围的_节点不应该包含节点中的所有对象(实际节点除外),因为每个对象都将满足上述语句,因为and对象将位于节点的上方或下方,或者位于节点的左侧或右侧 这段代码实际上只查找节点周围的节点(红方块) 有人能帮我理解这些if语句吗
谢谢只要用数字替换条件,你就会看到它是如何工作的
在上面的图像中,节点在行4和列4(基于0)上,让我们在行2上取TestPoad节点。 然后
if(test_node.rownode.row+1)
转化为
if (2 < 3 || 2 > 5 ) continue
如果(2<3|2>5)继续
“继续”表示“跳过此迭代的其余部分并开始下一个迭代”
现在,在第3行和第3列上使用test_节点
if ( 3 < 3 || 3 > 5 ) continue
if ( 3 < 3 || 3 > 5 ) continue
如果(3<3|3>5)继续
如果(3<3|3>5)继续
所有4个条件都为false,因此它会将其添加到周围的_节点
--编辑--
顺便说一句,如果你给你的循环贴上标签,那么发生的事情就更清楚了
iterateNodes : for(var i:uint = 0;i < nodes.length; i++){
test_node = this.nodes[i];
if (test_node.row < node.row - 1 || test_node.row > node.row + 1) continue iterateNodes;
if (test_node.column < node.column - 1 || test_node.column > node.column + 1) continue iterateNodes;
surrounding_nodes.push(test_node);
}
iterateNodes:for(变量i:uint=0;inode.row+1)继续迭代节点;
如果(test_node.columnnode.column+1)继续迭代节点;
推送(测试节点);
}
owww,“继续”就是这个意思。很高兴现在清楚了,在我的回答中给循环添加了一个标签,使其更加清楚。
if ( 3 < 3 || 3 > 5 ) continue
if ( 3 < 3 || 3 > 5 ) continue
iterateNodes : for(var i:uint = 0;i < nodes.length; i++){
test_node = this.nodes[i];
if (test_node.row < node.row - 1 || test_node.row > node.row + 1) continue iterateNodes;
if (test_node.column < node.column - 1 || test_node.column > node.column + 1) continue iterateNodes;
surrounding_nodes.push(test_node);
}