The initialization statement is executed once before the loop starts and is usually used to define and setup the loop variable. The typical format for a for loop looks like for (a b c) where a is the initialization statement, b is the condition statement, and c is the final expression. } //Our expected result is for our array to be after the loop finishes running.Ī for loop runs using three statements as part of its initialization. As an example, I will write some code here which takes a number and decreases it incrementally each time the code is ran until the number decreases to the point where it invalidates our condition: const qlcArray = More examples of the different kinds of loops can be found here in the MDN webdoc on loops and iteration.Ī while loop is a kind of loop that continues to run while a given condition is true and stops once that condition is no longer true. There are multiple kinds of loops we can utilizie in JavaScript, but this post will primarily focus on for loops and while loops. In the event we may need to run the same code multiple times, we can create a loop.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |