We are going to learn a really important topic today. I know this one is overwhelming at first, but if you practice then you’ll get this properly! Don’t just see the post of today, work on it too!
There are some different kind of loop in js but all they do the same work
for – loops through a block of code a number of times
for/in – loops through the properties of an object
for/of – loops through the values of an iterable object
while – loops through a block of code while a specified condition is true
do/while – also loops through a block of code while a specified condition is true
Most popular is for and while. We’ll learn both in your practice.
Sometimes we need to do the same task again and again. Like for adding sum of 10, 12 and 30 we need to add all these. First we need to work 10 + 12 then 22 + 30 again right ? Or we can add all three at a time, but suppose there is huge numbers like 500 numbers. What to do ?
We need to go through each and every number and add that to our total value. Which is going start from zero right?
We can do this work by loop. We can remove the doing same task again and again by using loop.
Lets see this
Understand something ?
We’ll work on loop code next tutorial.