Created
January 7, 2022 12:27
-
-
Save rashaabdulrazzak/22fc99abbe7ae75c3bc0a33c9057f21b to your computer and use it in GitHub Desktop.
loop in rust
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
fn main (){ | |
//define a for loop | |
for i in 0..3 { | |
println!("{}", i); | |
} | |
// define while loop | |
let mut x = 3; | |
while (x > 0){ | |
x -= 1 ; | |
println!("{}", x); | |
} | |
// define loop | |
// this will be infintie if we don't put a condition | |
//define an integer variable | |
let mut var = 1; | |
// define a while loop | |
loop { | |
var = var + 1; | |
println!("{}", var); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment