5 JavaScript Loops that you want to know about

1. For
2. While
3. Do While
4. For Of
5. For In
BONUS:
1. ForEach
2. For as a While

1. For Loop
This is the most well known Loop and I don’t recall any programming language without it. It has :
1. Counter Initialization
2. Stop condition
3. Step on every iteration


2. While Loop
This loop only focuses on the stopping condition. As long as you pass the condition the execution will still iterate the loop code
Note: When the total score crosses 100 it stopped going further.

3. Do While Loop
This is similar to the While loop except it guarantees that the code will execute once even if the condition is not met initially.
Note: The check is done at the end of execution. I am executing the do loop again after we crossed 100 and still it executed once

4. For Of
For of loop is a for loop with a simpler structure that guarantees to run for all array elements. It doesn’t care about indexes and similar to for each in someway

5. For In
This is a special kind of loop that iterates object keys In case you’re interested in Object properties this can be very helpful to use. You can still use it with Arrays, but ATTENTION that it may not follow the order

Courtesy: https://twitter.com/tobealy

Leave a comment

Your email address will not be published. Required fields are marked *