Skip to content

Instantly share code, notes, and snippets.

@Dineshs91
Created June 19, 2015 18:01
Show Gist options
  • Save Dineshs91/b750049ca0839baea326 to your computer and use it in GitHub Desktop.
Save Dineshs91/b750049ca0839baea326 to your computer and use it in GitHub Desktop.
FizzBuzz using match in rust
# 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