Iterating collections with forEach
📖 Scenario: You are helping a small bookstore manage its inventory. You have a list of book titles and want to print each title to check the stock.
🎯 Goal: Learn how to use the forEach function 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
forEach to print each book titlePrint the total number of books after listing them
💡 Why This Matters
🌍 Real World
Bookstores and libraries often need to list and count their inventory. Using <code>forEach</code> helps to process each item easily.
💼 Career
Knowing how to iterate collections is essential for many programming jobs, especially when working with data lists or user inputs.
Progress0 / 4 steps