Why loops are needed
📖 Scenario: Imagine you have a list of 5 friends and you want to say "Hello" to each one. Writing the same greeting again and again is tiring and takes a lot of space. Loops help us repeat actions easily without writing the same code many times.
🎯 Goal: You will create a list of friend names, set up a counter, use a loop to greet each friend, and finally print all greetings.
📋 What You'll Learn
Create a string array called
friends with these exact names: "Anna", "Ben", "Cara", "David", "Eva"Create an integer variable called
count and set it to 0Use a
while loop with the condition count < friends.Length to print greetingsInside the loop, print
"Hello, {friends[count]}!" using Console.WriteLineIncrease
count by 1 inside the loop💡 Why This Matters
🌍 Real World
Loops are used in many programs to repeat tasks like processing lists of data, showing menus, or handling user input multiple times.
💼 Career
Understanding loops is essential for any programming job because they help automate repetitive tasks efficiently.
Progress0 / 4 steps