ELSE
LET A = 3
PRINT A
ENDIF
This program prints 3; the reason for this is that A is initially set to 1, which is not more than 3;
therefore the ELSE part of the structure is executed; this sets A to 3 and then prints it.
Note that when you are typing in the program, the indentation does not matter. Indentation is
ignored by the compiler. It is only visually useful to make the program more human-readable.
4.8.3 GOTO
Causes program execution to jump to the specified line number.
Syntax:
GOTO <line number expression>
Line numbers are not necessary in QDOS BASIC. However if you want it to be possible to jump to
a particular line of code, then you must use a (unique) line number on that line, so that the GOTO
statement can find it.
The most common use is to allow a program to run repeatedly for ever. For example:
LET A = 1
10 PRINT A
LET A = A + 1
GOTO 10
This program sets variable A to 1, then prints it, then adds 1 to it. Finally the GOTO 10 statement
causes the program to jump to line 10. So it just prints, adds 1, and repeats ad infinitum. Running
the program prints the numbers to the terminal:
1
2
3
It just keeps on scrolling by, incrementing by one each time, until you halt the program.
4.8.4 Subroutines: GOSUB and RETURN
The GOSUB..RETURN structure is useful if you have a particular block of code, which we call a
subroutine, that you want to execute more than once in your program. Adding this kind of program
structure can be good practice in large programs as it keeps your program compact, efficient, neat
and readable.
Syntax:
GOSUB <line number expression>
RETURN
U4B operating manual Rev 1.00
35