For loop over collections
📖 Scenario: You work at a small bookstore. You have a list of book titles that you want to display one by one to your customers.
🎯 Goal: Learn how to use a for loop in Kotlin to go through each item in a list and print it.
📋 What You'll Learn
Create a list of book titles with exact values
Create a variable to count the number of books
Use a
for loop with variable book to iterate over the listPrint each book title inside the loop
Print the total number of books after the loop
💡 Why This Matters
🌍 Real World
Bookstores and libraries often need to show lists of books to customers or users. Looping through collections helps display or process each item easily.
💼 Career
Knowing how to loop over collections is a basic skill for any programmer. It helps in tasks like processing data, generating reports, or building user interfaces.
Progress0 / 4 steps