Why loops are needed
๐ Scenario: Imagine you have a list of fruits and you want to say hello to each fruit. Doing this one by one is slow and boring. Loops help us say hello to all fruits quickly and 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 a slice called
fruits with these exact values: "apple", "banana", "cherry"Create an empty slice of strings called
greetingsUse a
for loop with index i to go through fruitsInside the loop, add a greeting like
"Hello, apple!" to greetingsPrint each greeting from
greetings using a for loop๐ก Why This Matters
๐ Real World
Loops are used in many programs to handle lists of items, like showing all messages, processing orders, or checking data.
๐ผ Career
Understanding loops is essential for any programming job because they help automate repetitive tasks efficiently.
Progress0 / 4 steps