Skip to content

Instantly share code, notes, and snippets.

@hongsw
Created September 12, 2023 16:16
Show Gist options
  • Save hongsw/95bcceb24b881cbd4569e904cada5135 to your computer and use it in GitHub Desktop.
Save hongsw/95bcceb24b881cbd4569e904cada5135 to your computer and use it in GitHub Desktop.
FizzBuzz in Dart without IF

FizzBuzz in Dart without IF

Created with <3 with dartpad.dev.

void main() {
for (int i = 1; i <= 100; i++) {
String output = "";
var fizz = ["", "Fizz"];
var buzz = ["", "Buzz"];
output += fizz[i % 3 == 0 ? 1 : 0];
output += buzz[i % 5 == 0 ? 1 : 0];
print(output.isEmpty ? i.toString() : output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment