I was exploring the Google Closure Compiler, and one thing I noticed was that it converts while(true)
into for(;;)
.
Both do hang the browse
An empty middle part should be interpreted as true
, so it's not falsy. It has the same semantics in C and other languages with that kind of loop (like C#, Java and so on). It would be a real trap to have changed it for JavaScript.
There is evaluation algorothm of for loop in Standard ECMA-262 script that says there are only two situations in which loop will end:
From the ECMAScript language specification:
IterationStatement : for (ExpressionNoIn_opt ; Expression_opt ; Expression_opt) Statement
If the first Expression is present, then
Since the first expression (the second argument to for) is not present, this section is never run, so the for loop does not exit.
No, it is not true.
See: 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.
I should perhaps give a link to ECMAScript reference, but I'm pretty sure it states more or less same thing.