Edit this page

Don't need ELSE

Many forths contain the word else. Some, (like herkforth) don't. This page explains how you can do without it.

You can do without else by exiting the word. Here's the simplest case:

: foo ... if bar else baz then ;

can easily be coded:

: foo ... if bar exit then baz ;

In the following, it's a little trickier:

: foo ... if bar else baz then qux ;

When there's an else and stuff after then you need to refactor it into two definitions:

: -foo if bar exit then baz ;

: foo ... -foo qux ;

Yeah it's a bit more typing, but it makes you factor more.

Note: in colorforth and <herkforth

you use ; in place of exit which makes the else-less versions shorter than shown above.

See Also

forth

herkforth

herkforth words

Edit this page · home ·