James McGrath

Quick tips, in-depth guides, and thoughts on the future of the web

What Is a Loop?

🧪 Concept:

A loop is a way to repeat code automatically. Instead of writing the same line over and over, you tell the computer to repeat it for you.

Here’s a basic for loop:

for (let i = 0; i < 5; i++) {
console.log("Hi!");
}

This says:
▪ Start at 0
▪ Keep going while i is less than 5
▪ Add 1 each time
▪ Say “Hi!” each time through

🧰 Why It Matters:

Loops help you work through lists, repeat actions, and save yourself from writing the same thing again and again.

🎉 Quick Challenge:
Write a loop that counts from 1 to 3 and logs the number:

for (let i = 1; i <= 3; i++) {
console.log(i);
}

🧠 Fun Analogy:

A loop is like a record player on repeat. Once it starts, it keeps playing until you tell it to stop.

📚 Further Reading:
MDN Docs – Looping code
W3Schools – JavaScript Loops

Join us tomorrow!

Subscribe to my feed to follow along. I’ll keep the lessons short and sweet.

What Is an Object?

One response to “What Is a Loop?”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.