Skip to content

Instantly share code, notes, and snippets.

@namdiemefo
Created July 7, 2022 11:01
Show Gist options
  • Save namdiemefo/be9c5261b9834b7314c1111f874b0d3e to your computer and use it in GitHub Desktop.
Save namdiemefo/be9c5261b9834b7314c1111f874b0d3e to your computer and use it in GitHub Desktop.
void main() {
doFizzBuzz();
}
doFizzBuzz() {
// initialize variables
num fizzNumber = 0;
num buzzNumber = 0;
String word = "";
num x = 1;
while (x <= 100) {
// increment values
fizzNumber++;
buzzNumber++;
// attach and reset values
if (fizzNumber == 3) {
word += "Fizz";
fizzNumber = 0;
}
if (buzzNumber == 5) {
word += "Buzz";
buzzNumber = 0;
}
word.isEmpty ? print(x) : print(word);
word = "";
x++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment