Loop Execution Flow in Go
๐ Scenario: You are helping a small shop owner who wants to count how many items they have in stock. They have a list of item quantities and want to add them up.
๐ฏ Goal: Build a Go program that uses a for loop to add up all the item quantities and print the total.
๐ What You'll Learn
Create a slice named
items with the exact quantities: 3, 7, 2, 9, 4Create an integer variable named
total and set it to 0Use a
for loop with the variable quantity to go through each number in itemsAdd each
quantity to total inside the loopPrint the final value of
total๐ก Why This Matters
๐ Real World
Counting totals is common in shops, inventories, and anywhere you track quantities.
๐ผ Career
Understanding loop execution flow is essential for processing lists of data in software development.
Progress0 / 4 steps