DEV Community

davidka7
davidka7

Posted on

The for loop breakdown for javascript beginners

Even though the run time wasn't always the best, for loops still saved me in many grey areas, especially when solving algorithms and code challenges. For any javascript beginner even if you don't know many methods of javascript you can still use multiple for loops to solve it. Right now under this text I will break down for loop method using examples and showing the process, so that you can get the big overview on how it works.
Alt Text

Here you see the first statement
for (i=0;i<s.length;i++) here you set the standards for your loop method. I want my loop to start from 0 so I set at 0. And I want it to run the same function until a certain limit and so I set to run up to the length of s array, i<s.length. And for my last standard I set the increment, so that everytime it runs it will add one to the initial 0.
and then you run the function inside your function. As you can on the right side you get all values since the array had 4 elements it ran up to four times, each times incrementing the i by 1 and received 4 answers in return

Top comments (0)