Iterating over maps
📖 Scenario: You are managing a small store's inventory. You have a list of products with their stock counts. You want to check which products are available and print their names with the stock count.
🎯 Goal: Build a Go program that creates a map of products and their stock counts, then iterates over the map to print each product and its stock.
📋 What You'll Learn
Create a map called
inventory with string keys and int valuesAdd a variable called
minStock to set the minimum stock to consider a product availableUse a
for loop with range to iterate over inventoryPrint the product name and stock count only if the stock is greater than or equal to
minStock💡 Why This Matters
🌍 Real World
Managing inventory is a common task in stores and warehouses. Knowing how to store and check stock counts helps keep track of products.
💼 Career
Many programming jobs require working with maps or dictionaries to store and process data efficiently. Iterating over maps is a fundamental skill.
Progress0 / 4 steps