Skip to content

Instantly share code, notes, and snippets.

@georgematos
Created May 3, 2024 12:18
Show Gist options
  • Save georgematos/f2efe59332e3964c27de6497c5043705 to your computer and use it in GitHub Desktop.
Save georgematos/f2efe59332e3964c27de6497c5043705 to your computer and use it in GitHub Desktop.
Rust - loop and inner loop
// loop and inner loop
fn main() {
// this little piece of code is simply printing a counting 0 to 9
// whit a regressive counting 9 to 1 between each number
let mut count = 0;
'root_loop:loop {
println!("Count: {count}");
count += 1;
if count == 10 { break 'root_loop };
let mut count = 9;
loop {
print!("{count}");
count -= 1;
if count == 0 {
println!();
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment