Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


10.5.2 Labelling and the JUMP statement

A label names a position in a program, and these names are global (they can be referred to in any procedure). The most common use of label is with the JUMP statement, but you can also use labels to mark the position of some data (see 10.8 Assembly Statements). To define a label you write a name followed by a colon immediately before the position you want to mark. This must be just before the beginning of a statement, either on the previous line (by itself) or the start of the same line.

The JUMP statement makes execution continue from the position marked by a label. This position must be in the same procedure as the JUMP statement, but it can be, for instance, outside of a loop (and the JUMP will then have terminated that loop). For example, the following code fragments are equivalent:

  x:=1
  y:=2
  JUMP rubble
  x:=9999
  y:=1234
rubble:
  z:=88

  x:=1
  y:=2
  z:=88

As you can see the JUMP statement has caused the second group of assignments to x and y to be skipped. A more useful example uses JUMP to help terminate a loop:

  x:=1
  y:=2
  WHILE x<10
    IF y<10
      WriteF('x is \d, y is \d\n', x, y)
    ELSE
      JUMP end
    ENDIF
    x:=x+2
    y:=y+2
  ENDWHILE
end:
  WriteF('Finished!\n')

This loop terminates if x is not less than ten (the WHILE check), or if y is not less than ten (the JUMP in the IF block). This may seem pretty familiar, because it's practically the same as an example earlier (see 4.2.2 WHILE loop). In fact, it's equivalent to:

  x:=1
  y:=2
  WHILE (x<10) AND (y<10)
    WriteF('x is \d, y is \d\n', x, y)
    x:=x+2
    y:=y+2
  ENDWHILE
  WriteF('Finished!\n')


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.