Why loops are needed
📖 Scenario: Imagine you have a list of fruits and you want to say hello to each fruit one by one.
🎯 Goal: You will create a list of fruits, set up a counter, use a loop to greet each fruit, and then print all greetings.
📋 What You'll Learn
Create an array called
fruits with the values 'Apple', 'Banana', and 'Cherry'Create a variable called
count and set it to 0Use a
while loop with the condition $count < count($fruits)Inside the loop, print
Hello, followed by the fruit at index $countIncrement
$count by 1 inside the loop💡 Why This Matters
🌍 Real World
Loops are used in real life to do repeated tasks like sending emails to many people or checking every item in a list.
💼 Career
Knowing loops is important for any programming job because they help automate repetitive work efficiently.
Progress0 / 4 steps