Task

Write a program that prints the integers from   1   to   100   (inclusive).



But:

   for multiples of three,   print   Fizz     (instead of the number)
   for multiples of five,   print   Buzz     (instead of the number)
   for multiples of both three and five,   print   FizzBuzz     (instead of the number) 


The   FizzBuzz   problem was presented as the lowest level of comprehension required to illustrate adequacy.



Also see

   (a blog)   dont-overthink-fizzbuzz
   (a blog)   fizzbuzz-the-programmers-stairway-to-heaven


MODULE Fizzbuzz;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
 
TYPE CB = PROCEDURE(INTEGER);
 
PROCEDURE Fizz(n : INTEGER);
BEGIN
    IF n MOD 3 = 0 THEN
        WriteString("Fizz");
        Buzz(n,Newline)
    ELSE
        Buzz(n,WriteInt)
    END
END Fizz;
 
PROCEDURE Buzz(n : INTEGER; f : CB);
BEGIN
    IF n MOD 5 = 0 THEN
        WriteString("Buzz");
        WriteLn
    ELSE
        f(n)
    END
END Buzz;
 
PROCEDURE WriteInt(n : INTEGER);
VAR buf : ARRAY[0..9] OF CHAR;
BEGIN
    FormatString("%i\n", buf, n);
    WriteString(buf)
END WriteInt;
 
PROCEDURE Newline(n : INTEGER);
BEGIN
    WriteLn
END Newline;
 
VAR i : INTEGER;
BEGIN
    FOR i:=1 TO 30 DO
        Fizz(i)
    END;
 
    ReadChar
END Fizzbuzz.