๐ช๐ต๐ถ๐น๐ฒ ๐๐ผ๐ผ๐ฝ๐ ๐ถ๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐
JavaScript loops run code multiple times. They stop when a condition is false. This saves you time. It keeps your code clean.
The while loop is an entry control loop. It checks the condition first. If the condition is true, the code runs. If the condition is false, the loop stops.
Follow these steps:
- Set a start value.
- Check the condition.
- Run the code.
- Update the value.
Update your variable inside the loop. If you do not, the loop runs forever.
Example: let count = 0; while (count < 3) { console.log(count); count++; }
Output: 0 1 2