我有以下函数,但尽管使用了 break 语句,但它在数组中找到匹配项后似乎并没有停止:
private function CheckMatch() {
// _playersList is the Array that is being looped through to find a match
var i:int;
var j:int;
for (i= 0; i < _playersList.length; i++) {
for (j= i+1; j < _playersList.length; j++) {
if (_playersList[i] === _playersList[j]) {
trace("match:" + _playersList[i] + " at " + i + " is a match with "+_playersList[j] + " at " + j);
break;
} else {
// no match
trace("continuing...")
}
}
}
}
最佳答案
啊……我明白了。
使用了一个标签,现在它可以工作了:
private function CheckMatch() {
// _playersList is the Array that is being looped through to find a match
var i:int;
var j:int;
OuterLoop: for (i= 0; i < _playersList.length; i++) {
for (j= i+1; j < _playersList.length; j++) {
if (_playersList[i] === _playersList[j]) {
trace("match:" + _playersList[i] + " at " + i + " is a match with "+_playersList[j] + " at " + j);
break OuterLoop;
} else {
// no match
trace("continuing...")
}
}
}
}
关于actionscript-3 - 无法跳出嵌套的 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2050699/