Looping in JavaScript

Loop JavaScript

There are many cases when we need to do something repeatedly, like 100 times, 1000 times, or even more times. So, what if I tell you to console.log the value of some integer, then increment it, and again console.log the new incremented value of that integer, and if I tell you to do the same thing 100 times!!! are you going to write console.log and that all program for so many times?? NO WAY!

But thanks to loops, they make this thing so much easy for us to do.

Loop JavaScript

We are going to have a look at some of the loops in javascript, like the for loop, and while loop, and they do… while loop. But first of all, let’s get the overall idea about what we are going to do –

So, this is what we are going to do –
Step 1 – You have to write the code only once, that you want to execute A NUMBER OF TIMES!!
Step 2 – Put it inside the loop.
Step 3 – Run the program.

And yes… you are done. This is all we got to do. This is when we want to do something a number of times, we are going to make use of the loops.

As soon as we start making use of different loops, you would get used to it.

But if you are not getting the whole thing, just do not worry at all. Just understand that the loops are used for executing repeated operations/ instructions.

Well, as stated earlier, we are going to have a look at the for loop, and the while loop and they do… while loop.

So, let’s consider those loops one by one –