Created
October 3, 2018 12:05
-
-
Save epequeno/608409b3be8a878152beffa558bc16c6 to your computer and use it in GitHub Desktop.
examples of fizzbuzz in rust
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
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