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(){ | |
let date = 19; | |
let life = 35; | |
let miles = 91010101; | |
let x: 132 = 30; | |
let y: (i32, i64, u8) = (500, 900, 1); | |
// Multiple declaration. | |
} |
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(){ | |
let pi = 3.14; | |
let e = 2.718; | |
} |
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(){ | |
let my_array: [i32; 3] = [19, 24, 2]; | |
println!("The first element of the array is: {}", array[0]); | |
} |
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(){ | |
let a = (1, 1.5, true, 'a', "Hello, world!"); | |
// a.0 = 1, a.1 = 1.5, a.2 = true, a.3 = 'a', a.4 = "Hello, world!" | |
} |
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(){ | |
let str = "Hello! I'm a String"; | |
println!("The value of our variable is: {}", str); | |
} |
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(){ | |
let v = vec![1, 2, 3, 4, 5]; | |
println!("The third element of v is {}", v[2]); | |
} |
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(){ | |
let team_mem = 7; | |
if team_mem < 5 { | |
println!("Small"); | |
}else { | |
println!("Large"); | |
} | |
} |
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() { | |
let number = 19; | |
if number % 4 == 0 { | |
println!("number is divisible by 4"); | |
} else if number % 3 == 0 { | |
println!("number is divisible by 3"); | |
} else if number % 2 == 0 { | |
println!("number is divisible by 2"); | |
} else { |
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(){ | |
for x in 0..10 { | |
println!("{}", x); // x: i32 | |
} | |
} |
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() { | |
let mut a = 1; | |
while a <= 10 { | |
println!("Current value : {}", a); | |
a += 1; //no ++ or -- in Rust | |
} | |
} |