This file contains hidden or 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
// Simplest Example | |
let team_size = 7; | |
if team_size < 5 { | |
println!("Small"); | |
} else if team_size < 10 { | |
println!("Medium"); | |
} else { | |
println!("Large"); | |
} |
This file contains hidden or 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
let tshirt_width = 20; | |
let tshirt_size = match tshirt_width { | |
16 => "S", // check 16 | |
17 | 18 => "M", // check 17 and 18 | |
19 ... 21 => "L", // check from 19 to 21 (19,20,21) | |
22 => "XL", | |
_ => "Not Available", | |
}; | |
println!("{}", tshirt_size); // L |
This file contains hidden or 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
let mut a = 1; | |
while a <= 10 { | |
println!("Current value : {}", a); | |
a += 1; //no ++ or -- in Rust | |
} | |
// Usage of break and continue | |
let mut b = 0; | |
while b < 5 { | |
if b == 0 { |
This file contains hidden or 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 { | |
println!("Loop forever!"); | |
} | |
// Usage of break and continue | |
let mut a = 0; | |
loop { | |
if a == 0 { | |
println!("Skip Value : {}", a); | |
a += 1; |
This file contains hidden or 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
for a in 0..10 { //(a = 0; a <10; a++) // 0 to 10(exclusive) | |
println!("Current value : {}", a); | |
} | |
// Usage of break and continue | |
for b in 0..6 { | |
if b == 0 { | |
println!("Skip Value : {}", b); | |
continue; | |
} else if b == 2 { |
This file contains hidden or 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
/// Line comments; document the next item | |
/** Block comments; document the next item */ | |
//! Line comments; document the enclosing item | |
/*! Block comments; document the enclosing item !*/ |
This file contains hidden or 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
/// This module contains tests | |
mod test { | |
// ... | |
} | |
mod test { | |
//! This module contains tests | |
// ... |
This file contains hidden or 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
/// Foo | |
#[doc="Foo"] | |
//! Foo | |
#![doc="Foo"] |
This file contains hidden or 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
let a = 5; | |
let b = a + 1; //6 | |
let c = a - 1; //4 | |
let d = a * 2; //10 | |
let e = a / 2; // ⭐️ 2 not 2.5 | |
let f = a % 2; //1 | |
let g = 5.0 / 2.0; //2.5 |
This file contains hidden or 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
let a = 1; | |
let b = 2; | |
let c = a == b; //false | |
let d = a != b; //true | |
let e = a < b; //true | |
let f = a > b; //false | |
let g = a <= a; //true | |
let h = a >= a; //true |