[Previous] Lesson 2 [Next]

Basic Control Flow


Come Here's essential feature is its means of passing control between parts of the program.  Before this can be done, it is necessary to have some means of marking points in the program.  This is done by using labels.

A label is a non-negative integer literal that precedes a statement.  Any statement can have only one label, and no two statements can share the same label.

This code example includes a labelled statement:

    NOTE Example 2.1: Labelling a statement
10  TELL "Hello, world!" NEXT

An Apparent Ambiguity

Come Here is free-form like C.  This means that all whitespace characters (space, tab, newline) in the code are equivalent and completely interchangeable (except within a string).  Only the keywords serve to delimit statements in Come Here.  Consider this modification to Example 1.2:

NOTE Example 2.2: These two lines will run into each other
TELL 72 101 108 108 111 44 32 119 111 114 108 100 10
TELL "Goodbye, world!" NEXT

It appears that the 10 at the end of the first TELL statement could be either one of the arguments of TELL, or a label belonging to the next line.  The rule is that whenever this ambiguity occurs, it is taken to be a label.  Hence it will not be output as a character.

If the 10 is supposed to be an argument, then it must be separated from the following statement by using an empty string or something similar:

NOTE Example 2.3: Now they're separate again
TELL 72 101 108 108 111 44 32 119 111 114 108 100 10 ""
TELL "Goodbye, world!" NEXT

TELL must always have at least one argument, and so if TELL is followed immediately by a number then this number is always an argument and never a label.

Other than the TELL statement, only a NOTE is prone to this ambiguity, which can be avoided by not ending a comment with a number.  The issue doesn't apply to other statements that we will encounter later, since they take a fixed number of arguments.

Taking Control

The COME FROM statement seizes control from another part of the program. Unlike most statements, COME FROM doesn't do anything when the program counter reaches it.  Rather, after the statement with the specified label has been executed, control is automagically transferred to the point where the COME FROM statement lies.

So this program will keep on writing "Hello, world!" until the end of time, or until you can figure out some way of stopping it:

    NOTE Example 2.4: An infinite loop
    COME FROM 10
10  TELL "Hello, world!" NEXT

COME FROM can be also used to make conditional jumps, as we will see in Lesson 4.