Using a For Loop to Sum Numbers
📖 Scenario: You are helping a small shop owner who wants to add up the prices of some items they sold today.
🎯 Goal: Build a simple program that uses a for loop to add all the prices in a list and show the total amount earned.
📋 What You'll Learn
Create an array called
prices with the exact values: 10, 20, 30, 40, 50Create a variable called
total and set it to 0Use a
for loop with the variable i to go through each item in pricesAdd each price to the
total inside the loopPrint the
total after the loop finishes💡 Why This Matters
🌍 Real World
Adding up prices is a common task in shopping apps, cash registers, and budgeting tools.
💼 Career
Understanding loops and arrays is essential for many programming jobs, especially in web development and data processing.
Progress0 / 4 steps