Using a For Loop in Rust
๐ Scenario: You are helping a small shop owner who wants to list the prices of some fruits they sell. You will write a Rust program to show each fruit and its price.
๐ฏ Goal: Build a Rust program that uses a for loop to print each fruit and its price from a list.
๐ What You'll Learn
Create a vector called
fruits with tuples of fruit names and pricesCreate a variable called
count to count the number of fruitsUse a
for loop with variables name and price to iterate over fruitsPrint each fruit name and price inside the loop
Print the total number of fruits after the loop
๐ก Why This Matters
๐ Real World
For loops are used to process lists of items like products, prices, or user data in many programs.
๐ผ Career
Understanding for loops is essential for software development jobs where you handle collections of data efficiently.
Progress0 / 4 steps