Skip to main content
2 of 4
[Edit removed during grace period]
Mathieu Guindon
  • 75.6k
  • 18
  • 194
  • 468

FizzBuzz in Forth

There are quite a large number of existing implementatons of FizzBuzz but I awoke this morning in a cold sweat with the terrible revelation that Code Review had no FizzBuzz implementation in Forth! To redress this terrible oversight, I wrote this while sipping my first cup of coffee.

: FIZZBUZZ ( -- )
  CR 100 1 DO 
     I 3 MOD 0= I 5 MOD 0= 2DUP AND IF 
        ." fizzbuzz " 
     THEN IF 
        ." buzz " 
     THEN IF 
        ." fizz " 
     ELSE I . THEN 
  LOOP ;

I'm interested in a general review, including possible alternatives to the use of MOD, and whether further factoring should be used. For those unfamiliar with Forth, try http://www.forth.org/tutorials.html

Edward
  • 67.2k
  • 4
  • 120
  • 284