
However, personally, aesthetics matter to me (and it should to you if you are serious about the art of coding) a lot. That should not be a worry in today's age where you won't even notice the performance increase on a loop running for 10000 iterations on a 2.5 ghz quad core CPU. So it should run faster (on very large loop counts). Is one better than the other? Not in javascript (which you have tagged) as its not a compiled language.īut in languages like C++, a for loop usually gives the compiler a static count to loop which the compiler can use to optimize the binary. As soon as the condition fails, the loop is stopped.Functionally, one can substitute the other in all conditions. The while loop loops through a block of code as long as the specified condition evaluates to true. This is the simplest looping statement provided by JavaScript. In the following sections, we will discuss each of these loop statements in detail. for…of - loops over iterable objects such as arrays, strings, etc.


