red*_*ory 3 arrays loops break match actionscript-3
我有以下功能,但尽管使用了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...")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
red*_*ory 10
啊......我明白了.
使用标签,现在它的工作原理:
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...")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8701 次 |
| 最近记录: |