Why loops are needed
📖 Scenario: Imagine you have a list of fruits and you want to say hello to each fruit one by one. Doing this without loops means writing the same message many times. Loops help us repeat actions easily.
🎯 Goal: You will create a list of fruits, set up a counter, use a loop to greet each fruit, and finally print all greetings.
📋 What You'll Learn
Create an array called
fruits with these exact values: "Apple", "Banana", "Cherry"Create a variable called
greetings and set it to an empty arrayUse a
for loop with variable i to go through fruitsInside the loop, add a greeting string
`Hello, ${fruits[i]}!` to greetingsPrint the
greetings array💡 Why This Matters
🌍 Real World
Loops are used in many apps to process lists of items, like showing messages for each user or calculating totals.
💼 Career
Understanding loops is essential for any programming job because they make code efficient and easier to maintain.
Progress0 / 4 steps