0
0
Rustprogramming~15 mins

Loop execution flow in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Loop Execution Flow in Rust
๐Ÿ“– Scenario: You are helping a small bakery keep track of how many cakes they bake each day. They want to count cakes baked in a simple loop.
๐ŸŽฏ Goal: Build a Rust program that uses a loop to count cakes baked from 1 to 5 and then stops.
๐Ÿ“‹ What You'll Learn
Create a variable to count cakes baked
Use a loop to increase the count
Stop the loop when 5 cakes are counted
Print the final count
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Counting repeated actions like baked cakes helps bakeries track production easily.
๐Ÿ’ผ Career
Understanding loop flow is key for programming tasks that repeat steps until a condition is met.
Progress0 / 4 steps
1
Create a cake counter variable
Create a variable called cakes_baked and set it to 0.
Rust
Need a hint?

Use let mut to create a variable you can change later.

2
Set up a loop to count cakes
Add a loop block inside main that will run repeatedly.
Rust
Need a hint?

Use loop { } to create an infinite loop that you will control inside.

3
Increase the cake count and stop at 5
Inside the loop, add code to increase cakes_baked by 1 each time. Then use if cakes_baked == 5 to break the loop.
Rust
Need a hint?

Use += 1 to add one to the count. Use break to stop the loop.

4
Print the final cake count
After the loop, write println!("Cakes baked: {}", cakes_baked); to show the total cakes baked.
Rust
Need a hint?

Use println! to show the result on the screen.