javascript中出现意外的嵌套循环行为

Con*_*tch 0 javascript

我正在实现一种排序,我遇到了一些意想不到的行为:

var searches = ['beta', 'alpha'];
var i = 0; j = 0;

for(i = 0; i < searches.length; i++){
        min = i;

        // first time through, i = 0
         alert(i); 
        for(j = i; j<searches.length; j++);
        {
            // first time through j = 2. If i = 0, how does j = 2?
             alert(j); 
            // .. sort code
        }
}
Run Code Online (Sandbox Code Playgroud)

事实上,j总是2.为什么当进入for循环时j不被设置为i?

这是jsfiddle:http: //jsfiddle.net/w2kK9/3/

0x4*_*2D2 6

你有一个错位的分号:

for (j = i; j < searches.length; j++); // <--
Run Code Online (Sandbox Code Playgroud)

其余部分被解释为执行循环(何时j == 2)运行的块.

拿出来,它工作正常.