Loop construct in Rust
๐ Scenario: You are helping a small shop owner count the total number of items sold in a day. The shop owner has a list of daily sales numbers for each hour.
๐ฏ Goal: Build a Rust program that uses a loop construct to sum all the sales numbers and print the total.
๐ What You'll Learn
Create a vector called
sales with the exact values: 5, 8, 12, 3, 7Create a variable called
total and set it to 0Use a
loop construct with an index variable i to iterate over salesAdd each sale to
total inside the loopBreak the loop when all sales are added
Print the final
total value๐ก Why This Matters
๐ Real World
Counting totals from lists of numbers is common in sales, inventory, and data analysis.
๐ผ Career
Understanding loops and data structures like vectors is essential for software development and data processing jobs.
Progress0 / 4 steps