Amos Professional Manual  Contents  Index

Control Structures


Forced jumps
So far, it has been explained how certain jumps are made to another part of a program by logical decisions based on whether a situation is true or false. Similar jumps can be made whenever a particular variable is recognised, in other words, regardless of any other conditions. GOTO and GOSUB are examples of a "forced" jump.

ON
structure: jump on recognising a variable
On variable Proc list of procedures
On variable Goto list of numbered lines or labels
On variable Gosub list of numbered lines or labels

ON can be used to force the program to jump to a pre-defined position when it recognises a specified variable. Furthermore, jumps can be made to a choice of several positions, depending on what value is held by the variable at the time it is spotted. ON can force a jump to any of the following structures.

Procedures. When using an ON ... PROC structure, one or more named procedures is used as the target destination for a jump, depending on the contents currently held by a variable. Look at the following line:

X> On X Proc PROCEDURE1,PROCEDURE2

That is exactly the same as saying:

X> If X=1 Then PROCEDURE1
   If X=2 Then PROCEDURE2

It is important to note that procedures used in this way cannot include any parameters. If information is to be transferred to the procedure, it should be placed in a global variable, as explained in Chapter 5.5.

Goto is used to jump to one of a list of numbered lines, or a label, depending on the result of an expression. For example:

E> Print "Type in a value from 1 to 3"
   Input X
   On X Goto LABEL1,LABEL2,LABEL3
   LABEL1:
   Print "Ready"
   LABEL2:
   Print "Steady"
   LABEL3:
   Print "Go!"
Back    Next
05.04.10