Learning Goals
- Coming soon: How to repeat code with loops.
- Recognize repeated code patterns.
- Prepare your mindset for
forandwhile.
Core Logic
Loops help you repeat code. Before we learn loop syntax, we first train your thinking so loops feel easy.
for and while.If you print 3 messages, manual code is okay. If you print 100 messages, manual code is stressful.
console.log("Intern report 1");
console.log("Intern report 2");
console.log("Intern report 3");
console.log("Intern report 4");
When we write this repeatedly, we mean we are doing the same task many times. A loop will help us automate this in the next lesson.
Before coding loops, practice spotting the pattern:
console.log("Intern report ...").This lesson is intentionally a thinking lesson, not a syntax lesson. Many beginners struggle with loops because they jump into for and while before understanding repetition patterns. We are avoiding that trap. First, you train your eyes to see what repeats, what changes, and when repetition should stop.
When this mindset is strong, loop syntax becomes simple typing instead of confusion. You will not memorize loops blindly; you will understand why they exist and when to use them. That is the goal of this preparation step.
console.log lines manually for "Day 1" to "Day 5".Create a file named repeat-thinking.js and manually print "Task 1 complete" up to "Task 8 complete". In a comment, describe how a loop would reduce the code.
console.log("Task 1 complete");
console.log("Task 2 complete");
console.log("Task 3 complete");
console.log("Task 4 complete");
console.log("Task 5 complete");
console.log("Task 6 complete");
console.log("Task 7 complete");
console.log("Task 8 complete");
// A loop can run one block many times instead of writing each line.