Forth FizzBuzz
Here is the word:
: FIZZBUZZ ( n -- )
DUP 1+ 1 DO
I 15 MOD 0= IF ." FizzBuzz "
ELSE I 3 MOD 0= IF ." Fizz "
ELSE I 5 MOD 0= IF ." Buzz "
ELSE I .
THEN THEN THEN
LOOP ;
It takes n from the stack and prints 1 through n.
What I like about it is that the shape is very Forth:
DO ... LOOPis the structureMODdecides the branch."prints the right word without leaving the stack noisy
The whole thing fits in the language instead of fighting it.
💬 Comments
Leave a comment