actionscript-3 - 无法跳出嵌套的 for 循环

标签 actionscript-3 arrays loops match break

我有以下函数,但尽管使用了 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/

相关文章:

PHP preg_match 查找相关单词

c++ - 如何在 C++ 中声明不同大​​小的数组?

javascript - Javascript for 循环中的意外标识符

css - AS3 的 CSS 标识符中的错误?

apache-flex - 柔性 : HTTP request error #2032

c++ - 将对象分配给数组 C++

python - 循环为给定范围的数字创建新行

JavaScript forEach 循环使用 .push() 将一个数组分成其他数组

actionscript-3 - SEO , Flash 和来自外部文件的数据

flash - 帮助 - 使用 stage.addEventListener (ScrollBar) 时出现空对象错误