Fizzbuzz with two if-statements

What’s fizzbuzz?

According to

The “Fizz-Buzz test” is an interview question designed to help filter out the 99.5% of programming job candidates who can’t seem to program their way out of a wet paper bag. The text of the programming assignment is as follows:
“Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”

Everyone who knows to program a little bit can solve this problem.
However, there is something in there that makes the naive solution seem to be a bit ugly and I always wanted to find a way to overcome this. That is, to write the naive code, one would check for divisibility by 3 and divisibility by 5. To check divisibility by 15, one could use the flags obtained by the previous checks or make a new check for divisibility by 15.

Continue reading “Fizzbuzz with two if-statements”