Skip to content

Instantly share code, notes, and snippets.

@georgematos
Last active May 3, 2024 13:00
Show Gist options
  • Save georgematos/289dbc413bef0d6c39c7568a6d297ae7 to your computer and use it in GitHub Desktop.
Save georgematos/289dbc413bef0d6c39c7568a6d297ae7 to your computer and use it in GitHub Desktop.
Rust - loop vs while vs for
fn main() {
let mut count = 3;
loop {
if count > 0 {
println!("{count}!");
count -= 1;
} else {
break
}
}
println!("LIFTOFF!");
let mut count = 3;
while count > 0 {
println!("{count}!");
count -= 1;
}
println!("LIFTOFF!");
for number in (1..4).rev() {
println!("{number}!")
}
println!("LIFTOFF!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment