For loops
📖 Scenario: You work in a small store and want to calculate the total price of items bought by a customer. Each item has a price, and you want to add them all up.
🎯 Goal: Build a MATLAB program that uses a for loop to add up the prices of items in a list and print the total cost.
📋 What You'll Learn
Create a vector called
prices with the exact values: 10, 20, 15, 5, 30Create a variable called
total and set it to 0Use a
for loop with the variable i to iterate over the elements of pricesAdd each price to
total inside the loopPrint the final value of
total using disp💡 Why This Matters
🌍 Real World
Calculating totals is common in stores, restaurants, and anywhere money is counted.
💼 Career
Understanding loops and summing values is a basic skill for data analysis, finance, and programming jobs.
Progress0 / 4 steps