CDC Community

🔹 Historical Conservation 🔹

User Tools

Site Tools


The -goto- Command

The -goto- command is a very mild version of the -jump- command. It does not initiate a new main unit and does not perform the initializations associated with starting a main unit (the screen is not erased, the help and other unit pointers are not cleared, and how deep we are in “do” levels is unaffected). It is most often used in its conditional form so we waited until this chapter to introduce it.

One common use of the -goto- command is to “cutoff” a unit prematurely:

unit A at 1315 write You have now finished the quiz. goto score<90,fair,x size 4 at 2205 write Congratulations! size 0 * unit B at 1912 write The next topic is ..... . . . unit fair at 1815 write Your score was below 90. * unit blah . . .

In this example, a score of 90 or better will mean that we fall through the -goto- to display the large-size “Congratulations!” A score of less than 90 will take us to unit “fair” to add “Your score was below 90” to the “You have finished the quiz” already on the screen. The -goto- does not erase the screen, nor does it change the fact that the main unit is still “A”. When the student presses NEXT, he proceeds to unit “B”, the main unit following unit “A”. He does not proceed to unit “blah”.

Like -do-, the -goto- command attaches a unit without changing which unit is “home”, whereas -jump- changes the main unit and performs the many initializations associated with entering a new main unit (full-screen erase, clearing the help pointers, forgetting any -do-s, etc.). The main difference between -goto- and -do-, is that the -do- will normally come back upon completion of the attached unit, whereas -gotodoes not come back and statements following the -goto- are normally not executed. (Some people like to think of the -goto- coming back to the end of the unit, whereas -do- comes back to the next statement.)

The relationships among main units and attached units and among -jump-, -goto-, and -do- may be clearer if you think of a lesson as being made up of a number of nodes or clusters, each consisting of a main unit and its attached units:

Movement between main units is made by pressing NEXT (or HELP, BACK, etc.) or by executing a -jump-. These main units may form a normal sequence or a help sequence (see Chapter 5). The -goto- and -docommands attach auxiliary units to these main units.

Notice that completion of a unit reached by one or more -goto-s will cause TUTOR to “undo” one level, if one or more -do-s had intervened in reaching this unit. The reason this occurs is that whenever TUTOR encounters a -unit- command (which terminates the preceding unit) TUTOR asks “Are we at the main-unit level?” If so, we have completed processing; if not, we must “undo” to the statement immediately following the last -do- encountered. This point deserves an illustration:

unit calcit do sum show total unit sum calc total⇐0 $$ initialize "total" goto addup $$ -goto- used instead of -do-, for * $$ purposes of illustration unit addup . . $$ a calculation of "total" . unit other

In unit “calcit” we -do- “sum”, which initializes “total” and does a -goto- to unit “addup”, where some kind of calculation is performed. When we run out of work (by encountering a -unit- command at the end of unit “addup”), TUTOR asks whether there was a -do-. There was a -do-, so control passes to the statement following the last -do-, which is “show total”. All of this is perfectly reasonable and useful, but it should be pointed out that this property of the -goto- (that it preserves the required information to permit “undoing”) has an odd side-effect. The presence of a -goto- in a done unit causes an exception (the only exception) to the description of -do- as a text-insertion device. Except for this case, the effect of a -do- is equivalent to inserting all the statements, contained in the done unit, in place of the -do- statement. But suppose we replace our -do- with the statements contained in unit “sum”. We would have:

unit calcit calc total⇐0 $$in place of "do sum" goto addup show total * unit addup . . unit other

Now the -goto- cuts off the rest of unit “calcit”, and the -show- will not be performed, in contrast with the case where we used a -do-. So, the presence of a -goto- in a done unit causes a (useful) exception to the text-insertion nature of -do-.

Here is a summary of the basic properties of the -goto- command:

  1. -goto- may be used to attach units with none of the initializations

associated with -jump-;

  1. statements which follow the -goto- will not be executed (like

-jump- and unlike -do-);

  1. a -goto- in a done unit does not cut off statements following the

original -do- statement, which is an exception to the normal text-insertion nature of -do-.

Additional aspects of -goto- (in relation to judging student responses) are discussed in Chapter 8.

It is often convenient to cut off a unit with a -goto- in the form shown in this example:

unit cuts goto expression,x,zonk,empty,x,empty write We fell through . . . . . . unit empty * unit zonk . . .

Note that unit “empty” has nothing in it but serves merely to have a place to go to in order to cut off the end of unit “cuts”. This is such a common situation that TUTOR provides an empty unit named “q” (for quit). The previous -goto- can be written as:

goto expression,x,zonk,q,x,q

The statement “goto q” means go to an empty unit. The special meaning of “q” here makes it illegal to have your own unit named “q”, just as it is not possible to name a unit “x”. Since “do empty” can be rendered by the equivalent “do x”, the statement “do q” (or a conditional form) is given the special interpretation of acting like a “goto q”. The use of “q” in a -goto- statement is somewhat different from the use of “q” in a -help- statement. You will recall from Chapter 5 that “help q” means to quit specifying a help unit, by clearing the -help- pointer.

The -goto- can be used in association with the -entry- command to skip over statements:

calc b⇐0 goto 3f>5,leavit,x calc b⇐f/2 f⇐0 entry leavit . . .

If 3f is greater than 5, we skip over intervening statements to entry “leavit”. The -entry- command is equivalent to a special -goto- plus a -unit-:

. . . special goto leavit unit leavit . . .
the above is the equivalen tot entry leavit

So, unlike a -unit- command, -entry- does not terminate a unit but merely provides a named place to branch to. Its equivalence to a special hidden -goto- followed by a -unit- command means that an entry is completely equivalent to a unit, except for not terminating the preceding statements. For this reason it is possible to use an entry name with -do-, -jump-, -help-, etc.

The conditional -goto- is often used for repetitive operations similar to those carried out with -do-. Here are two versions of a subroutine to add the cubes of the first ten integers:

The last two statements in the -goto- example could be combined as:

goto (i⇐i+1)≤10,add2,x

For the simple task of adding ten numbers, the -do- form is certainly easier to construct, but situations occasionally arise where it is easier to construct a repetitive loop using a conditional -goto-.

Except for not changing how many levels deep in -do-s we are, -gotois quite similar to -do-. Although the feature is seldom used, it is even possible to pass arguments to a subroutine with a -goto-:

goto zonk(12,25)

Arguments may also be passed in a conditional -goto-:

goto 3N-4,alpha(2+count),x,beta(15,2N),q

The Conditional Iterative -do-

tutor/goto_command.txt · Last modified: 2022/08/25 13:29 by site_admin