The Big Idea
What if you could tell the computer to do boring tasks for you, perfectly every time?
What if you could tell the computer to do boring tasks for you, perfectly every time?
Imagine you have a big stack of papers and you need to stamp each one. Doing it by hand, one by one, is tiring and slow.
Manually repeating the same action over and over wastes time and can cause mistakes, like missing a paper or stamping twice.
A loop lets the computer repeat tasks automatically, so you can handle many items quickly and without errors.
println!("Stamp paper 1"); println!("Stamp paper 2"); println!("Stamp paper 3");
for i in 1..=3 { println!("Stamp paper {}", i); }
Loops let you automate repetitive tasks, saving time and reducing mistakes.
Counting how many times a player scores in a game by checking each round automatically.
Loops repeat actions without writing the same code many times.
They make programs faster and less error-prone.
Loops help handle many items easily.