๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐๐ผ๐ผ๐ฝ๐
You need loops to run code multiple times. JavaScript has three main types.
The For Loop This loop uses three parts.
- Part 1: Set your start value.
- Part 2: Set the condition to stop.
- Part 3: Change the value after each turn.
Loop Scope Where you put your variable matters.
- Declare it outside the loop. You use it after the loop ends.
- Declare it inside with let. You use it only inside the loop.
The While Loop This loop runs as long as a condition is true.
- It checks the condition first.
- If the condition is false, the code never runs.
The Do While Loop This loop is different.
- It runs the code once first.
- Then it checks the condition.
- The code always runs at least once.
One warning. Update your variable. The loop never ends if you do not.
Source: https://www.w3schools.com/js/js_loops.asp Source: https://www.geeksforgeeks.org/javascript/loops-in-javascript/ Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration Optional learning community: https://dev.to/dev_saravanan_journey/javascript-loops-31lh