Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty for loop - for(;;)

Tags:

javascript

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?

like image 761
pimvdb Avatar asked Jan 19 '11 21:01

pimvdb


People also ask

What does an empty for loop do in Java?

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.

What is an empty for loop explain with an example?

An empty loop is a loop which does not have any updation or value of iteration. An empty loop is infinite.

Is an empty for loop 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.

What is an empty loop in Python?

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.


1 Answers

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.

like image 120
Mchl Avatar answered Oct 10 '22 22:10

Mchl