RosettaCodeData/Task/Conditional-structures/Forth/conditional-structures-6.fth

16 lines
311 B
Forth

: CASE: ( <name>) CREATE ;
\ lookup execution token and compile
: | ( <name> ) ' compile, ;
: ;CASE ( n -- ) DOES> OVER + + @ EXECUTE ;
: FOO ." FOO" ;
: BAR ." BAR" ;
: FIZZ ." FIZZ" ;
: BUZZ ." BUZZ" ;
CASE: SELECT ( n -- ) | FOO | BAR | FIZZ | BUZZ ;CASE
\ Usage: 3 SELECT