Created
August 29, 2013 01:58
-
-
Save SamRH/6373497 to your computer and use it in GitHub Desktop.
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
// the various moudules im going to use | |
use std::int; | |
use std::io; | |
// see comment for bang but 3 | |
fn fizz(i: int) -> bool { | |
i % 3 == 0 | |
} | |
// function using an implicit return to evaluate divisibility by 5 | |
fn bang(i: int) -> bool { | |
i % 5 == 0 | |
} | |
// main function aka entry point | |
fn main() { | |
// iterate a range, assigning each iter to num | |
for int::range(1, 101) |num| { | |
// print a line... | |
io::println( | |
// match a tuple (match is kinda like C-switch) | |
match (fizz(num), bang(num)) { | |
(true, true) => ~"FizzBuzz", | |
(true, false) => ~"Fizz", | |
(false, true) => ~"Buzz", | |
_ => fmt!("%d", num) /* could have matched | |
w/(false, false), _ is all */ | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment