Array iteration and enumerated
📖 Scenario: You are helping a small bookstore keep track of book titles and their positions on a shelf.
🎯 Goal: You will create an array of book titles, then use enumerated() to print each book's position and title.
📋 What You'll Learn
Create an array called
books with exactly these titles: "Swift Basics", "iOS Development", "Data Structures"Create a variable called
startIndex and set it to 1Use a
for loop with enumerated() on books to get index and titlePrint the position starting from
startIndex and the book title in the format: "Book 1: Swift Basics"💡 Why This Matters
🌍 Real World
Bookstores or libraries often need to list items with their positions or numbers for easy reference.
💼 Career
Knowing how to loop through arrays with indexes is important for many programming tasks like displaying lists, processing data, or creating menus.
Progress0 / 4 steps