๐—จ๐—ป๐—ฑ๐—ฒ๐—ฟ๐˜€๐˜๐—ฎ๐—ป๐—ฑ๐—ถ๐—ป๐—ด ๐—Ÿ๐—ผ๐—ผ๐—ฝ๐—ถ๐—ป๐—ด ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜

Stop writing the same code over and over. It wastes time. Use loops instead.

A loop runs a block of code until a condition is false.

Take a while loop. It runs code as long as the condition is true.

Every loop needs three parts:

Example: let i = 1; while (i <= 5) { console.log(i); i++; }

The code starts at 1. It prints the number. It adds 1. It stops at 5.

Be careful. Always update your variable. If you forget, the loop runs forever. This is an infinite loop.

Use loops for these tasks:

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration Source: https://www.w3schools.com/js/js_loop_while.asp Source: https://javascript.info/while-for Optional learning community: https://dev.to/annapoo/understanding-looping-in-javascript-2did