I was exploring the Google Closure Compiler, and one thing I noticed was that it converts while(true)
into for(;;)
.
Both do hang the browser, but why does the empty for
loop not break out of itself immediately? The second part of it is empty, and therefore falsy. Isn't it true that when the second part is falsy, the for
loop stops and execution continues with code which comes after the for
loop?
Could someone perhaps give an explanation for this?
It has no initialization statement, so nothing will be executed. Its conditional check statement is also empty, which means it evaluates to true after that the loop body is executed.
An empty loop is a loop which does not have any updation or value of iteration. An empty loop is infinite.
An empty loop is a loop that doesn't contain any executable statement, whereas, an infinite loop is a loop that runs an infinite number of times. An empty loop contain only one empty statement. They are mostly used to produce time breaks. for(int a=0;a<10;a++); An infinite loop on the other hand continues forever.
pass is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With