Created
October 22, 2021 22:24
-
-
Save Shaun289/871f2c5399bf00eca5c5c44d265a5fa5 to your computer and use it in GitHub Desktop.
rust study : match
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
/* | |
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match.html | |
compiled on https://play.rust-lang.org/ | |
Notice : exclusive range patterns https://github.com/rust-lang/rust/issues/37854 | |
*/ | |
fn main() | |
{ | |
for number in 1..22 { | |
println!("Tell me about {}", number); | |
match number { | |
1 => println!("One!"), | |
2 | 3 | 5 | 7 | 11 => println!("{} is a prime.", number), | |
13..=20 => println!("A teen"), | |
_ => println!("Ain't special") | |
} | |
} | |
let b = true; | |
let binary = match b { | |
false => 0, | |
true => 1, | |
}; | |
println!("{} -> {}", b, binary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment