Created
May 3, 2024 12:18
-
-
Save georgematos/f2efe59332e3964c27de6497c5043705 to your computer and use it in GitHub Desktop.
Rust - loop and inner loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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