Created
May 12, 2015 07:31
-
-
Save Manuzor/fbcba7d15f5a40cb9c5f to your computer and use it in GitHub Desktop.
FizzBuzz with two conditionals
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
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