๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐ช๐ต๐ถ๐น๐ฒ ๐๐ผ๐ผ๐ฝ๐
Loops run code multiple times. They run as long as a condition is true. They stop you from repeating code.
The while loop works like this:
- It checks the condition first.
- It runs the code if the condition is true.
- It stops if the condition is false.
Look at these examples.
Count down from 5 to 1: let i = 5; while (i >= 1) { console.log(i); i--; }
Print 1 five times: let count = 0; while (count < 5) { console.log(1); count++; }
Practice builds skills. Solving problems shows how loops work. Documenting your journey helps you learn.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration Source: https://www.geeksforgeeks.org/javascript/loops-in-javascript/ Optional learning community: https://dev.to/kamalesh_ar_6252544786997/looping-statements-and-its-concepts-53jj