𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗟𝗼𝗼𝗽𝗶𝗻𝗴 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁𝘀
Loops run a block of code many times. They stop repetition. They make your program clean.
The while loop runs as long as a condition is true. It checks the condition first. This is an entry control loop.
How a while loop works:
- It checks if the condition is true.
- It runs the code inside.
- It updates a value.
- It checks the condition again.
If the condition is false, the loop stops.
Example 1: Print 5 to 1 Set i to 5. While i is 1 or more, print i. Subtract 1 from i.
Example 2: Print 1 five times Set count to 0. While count is less than 5, print 1. Add 1 to count.
Practical work helps you learn. Solve problems to see how loops work. Write blogs to remember what 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