Once the condition evaluates to false then (and only then) will the while loop stop looping. The while loop keeps looping while a specific condition is true. This is in stark contrast to the while loop. We know exactly how many times a for loop will iterate once the code is running and the JavaScript engine starts executing the for loop's code. You see, the for loop has a specific and predefined number of iterations that it will make. The difference between these two loops is how they decide to STOP looping. What's the Difference Between a WHILE Loop and a FOR Loop? Let me take a minute to explain the difference between these two types of loops. Again, if you aren't familiar with the for loop, please review the topic here. This is very similar to the for loop with one important difference. The main goal of the while loop is to continually re-run a specific chunk of code over and over again. For a review on what a control structure is, please see our last post on IF statements. You use a while loop when you are now not positive how many times you will execute the loop body and the loop body can also not execute even once.The while loop in JavaScript is yet another type of control structure. In JavaScript, the while loop is a fundamental manipulate statement that allows you to operate a repetitive action. This JavaScript tutorial explains how to use the while loop with syntax and examples.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |