Imagine you need to write "Hello" 100 times. You could type it out manually 100 times, but that would be tedious and time consuming. Loops are a way to tell the computer to repeat an action multiple times automatically.
Loops help us avoid repetitive work. Instead of writing the same code many times, we write it once and tell the computer how many times to repeat it. This makes our code shorter, cleaner, and easier to manage.
JavaScript has several types of loops, but here are the three most common ones:
Watch the following videos about a quick introduction to the for loop in JavaScript.
https://www.youtube.com/watch?v=s9wW2PpJsmQ
<aside> ⚠️
There are multiple for loops in JavaScript. You may see for(x in y) , for(x of y) or even x.forEach(...). For the technical assignment, we only focus on the first type of for loop for (let i = 0; i< 10; i++)
</aside>
Perhaps a simpler loops is called the while loop. In this video you can learn how to make a simple login and password in JavaScript
https://www.youtube.com/watch?v=TDUz9QcGPoE
<aside> 💡
Everything you can do with a while loop, you can also do with a for loop. The difference is in the style. Sometimes it is more convenient to use one loop over the other.
</aside>