Created
June 19, 2015 18:01
-
-
Save Dineshs91/b750049ca0839baea326 to your computer and use it in GitHub Desktop.
FizzBuzz using match 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
# Method 1 | |
fn main() { | |
for x in 1..101 { | |
match x { | |
x if x % 15 == 0 => println!("{} FizzBuzz", x), | |
x if x % 5 == 0 => println!("{} Buzz", x), | |
x if x % 3 == 0 => println!("{} Fizz", x), | |
_ => println!("{}", x), | |
} | |
} | |
} | |
# Method 2 | |
fn main() { | |
for x in 1..101 { | |
match x { | |
_ if x % 15 == 0 => println!("{} FizzBuzz", x), | |
_ if x % 5 == 0 => println!("{} Buzz", x), | |
_ if x % 3 == 0 => println!("{} Fizz", x), | |
_ => println!("{}", x), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment