Skip to content

Instantly share code, notes, and snippets.

@Manuzor
Created May 12, 2015 07:31
Show Gist options
  • Save Manuzor/fbcba7d15f5a40cb9c5f to your computer and use it in GitHub Desktop.
Save Manuzor/fbcba7d15f5a40cb9c5f to your computer and use it in GitHub Desktop.
FizzBuzz with two conditionals
module fizzbuzz;
import std.stdio : writefln;
import std.conv : to;
void fizzbuzz(int i) {
auto msg1 = i.to!string;
auto msg2 = "";
if (i % 3 == 0) {
msg1 = "";
msg2 ~= "Fizz";
}
if (i % 5 == 0) {
msg1 = "";
msg2 ~= "Buzz";
}
writefln("%s%s", msg1, msg2);
}
void main() {
for (int i = 0; i < 100; ++i) {
fizzbuzz(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment