Rust Loops Tutorial | loop while for for Beginners (2024)

5views
1likes
0
6:55
T
Taught by Celeste AI - AI Coding Coach
View on YouTube
Description
Learn all three types of loops in Rust with a relaxed, beginner-friendly pace! This tutorial covers loop with break, while loops with conditions, and for loops with ranges. šŸ”„ In This Tutorial: ━━━━━━━━━━━━━━━━━━━━━━━ 0:00 - Introduction 0:11 - Basic loop with break 2:30 - While Loop (Countdown Timer) 4:53 - For Loop with Range šŸ“š What You'll Learn: ━━━━━━━━━━━━━━━━━━━━━━━ āœ… The infinite 'loop' keyword and how to break out āœ… While loops that check conditions each iteration āœ… For loops with range syntax (1..6 vs 1..=5) āœ… Using 'mut' for mutable variables āœ… When to use each loop type šŸ’» Code Examples: ━━━━━━━━━━━━━━━━━━━━━━━ Example 1 - Basic Loop with Break: fn main() { let mut count = 0; loop { count = count + 1; println!("Count is: {}", count); if count == 5 { break; } } } Example 2 - While Loop Countdown: fn main() { let mut seconds = 5; while seconds is greater than 0 { println!("{} seconds remaining...", seconds); seconds = seconds - 1; } println!("Liftoff!"); } Example 3 - For Loop with Range: fn main() { for number in 1..6 { println!("Number: {}", number); } } // Note: 1..6 gives 1,2,3,4,5 (6 is excluded) // Use 1..=5 for inclusive range šŸ¦€ Key Takeaways: ━━━━━━━━━━━━━━━━━━━━━━━ • loop runs forever until break is called • while checks a condition before each iteration • for is best for iterating over ranges • 1..6 excludes the end, 1..=5 includes it • Use 'mut' when you need to change a variable šŸ“Œ Prerequisites: ━━━━━━━━━━━━━━━━━━━━━━━ • Rust installed (rustc --version) • Basic understanding of Rust syntax • Watch our previous Rust tutorials! šŸ‘ Like, Subscribe & Share for more Rust tutorials! #Rust #RustLang #Programming #Loops #ForLoop #WhileLoop #Coding #Tutorial #LearnRust #Beginner #rustlang2024
Back to tutorials

Duration

6:55

Published

December 21, 2025

Added to Codegiz

March 15, 2026

Open in YouTube