"Mix 'n' Match"

Control Structures

Forth is a structured language. It does not have a GOTO. It does not have a compiler option to enable GOTO's.

What it does have is a set of words that can be used to construct the regular control structures, and some more complex constructs for those times when other languages send you racing for a GOTO.

The most common control flow words are;

The words IF UNTIL and WHILE take a flag from the stack, and branch if the flag was FALSE (non-zero). The other words have no stack effect.

These can be used to make;

As well as such esoteria as; Which is a loop with two exit points.
As there is a simple mapping between stack operators and stackFlow diagrams in Forth, so there is a simple relationship between control flow diagrams and control flow words.

I am indebted to Wil Baden for having made this relationship clear, and use his "flowgraphs" on this page to illustrate that mapping.

In the next section we look at how stackFlow diagrams can be combined with flowgraphs, and see some applications of control flow words.

Go on to the next section.
Return to the contents page.