我对一些轻早读拉升NWmatcher source code,发现这个代码奇数位我从来没有在JavaScript见过:这是什么:main:for(...){...}在做什么?
main:for(/*irrelevant loop stuff*/){/*...*/}
这个片段可以在compileGroup
方法来发现线441(nwmatcher- 1.1.1)
return new Function('c,s,d,h',
'var k,e,r,n,C,N,T,X=0,x=0;main:for(k=0,r=[];e=N=c[k];k++){' +
SKIP_COMMENTS + source +
'}return r;'
);
现在我想出了什么main:
是我自己做的。如果你在一个循环中有一个循环,并且想跳到外循环的下一个迭代(没有完成内部或外部循环),你可以执行continue main
。例如:
// This is obviously not the optimal way to find primes...
function getPrimes(max) {
var primes = [2], //seed
sqrt = Math.sqrt,
i = 3, j, s;
outer: for (; i <= max; s = sqrt(i += 2)) {
j = 3;
while (j <= s) {
if (i % j === 0) {
// if we get here j += 2 and primes.push(i) are
// not executed for the current iteration of i
continue outer;
}
j += 2;
}
primes.push(i);
}
return primes;
}
这是什么叫?
有没有不支持它的浏览器?
除continue
以外,是否还有其他用途?