Skip to content

Instantly share code, notes, and snippets.

@epequeno
Created October 3, 2018 12:05
Show Gist options
  • Save epequeno/608409b3be8a878152beffa558bc16c6 to your computer and use it in GitHub Desktop.
Save epequeno/608409b3be8a878152beffa558bc16c6 to your computer and use it in GitHub Desktop.
examples of fizzbuzz in rust
fn use_match() {
for i in 1..20 {
match (i%3, i%5) {
(0,0) => println!("FizzBuzz"),
(_,0) => println!("Buzz"),
(0,_) => println!("Fizz"),
(_,_) => println!("{}", i)
}
}
}
fn use_if() {
for i in 1..20 {
if i % 15 == 0 {
println!("FizzBuzz");
} else if i % 5 == 0 {
println!("Buzz");
} else if i % 3 == 0 {
println!("Fizz");
} else {
println!("{}", i);
}
}
}
fn main() {
// use_match();
use_if();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment