我正在探索 Google Closure Compiler ,我注意到的一件事是它将 while(true)
转换为 for(;;)
。
两者都会挂起浏览器,但为什么空的 for
循环不会立即跳出自身?它的第二部分是空的,因此是虚假的。当第二部分为假时,for
循环停止并继续执行 for
循环之后的代码,这不是真的吗?
有人可以对此给出解释吗?
最佳答案
不,这不是真的。
参见:https://developer.mozilla.org/en/JavaScript/Reference/Statements/for
condition
An expression to be evaluated before each loop iteration. If this expression evaluates to true, statement is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the for construct.
我或许应该提供一个指向 ECMAScript 引用的链接,但我很确定它或多或少地陈述了同样的事情。
关于javascript - 空 for 循环 - for(;;),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4740979/