PROGRAM |
![]() ![]() ![]() |
The PROGRAM statement introduces a program.
Format
PROGRAM name
where
QMBasic programs should commence with a PROGRAM, SUBROUTINE, FUNCTION or CLASS statement. If none of these is present, the compiler behaves as though a PROGRAM statement had been used with name as the name of the source record.
The PROGRAM statement must appear before any executable statements.
The name need not be related to the name of the source record though this eases program maintenance. The name must comply with the QMBasic name format rules.
A program module may be entered by referencing it a RUN command, by executing a command name that corresponds to the name of the program in the system catalogue, or by use of the QMBasic CALL statement in another program.
Example
PROGRAM SUM TOTAL = 0 LOOP DISPLAY TOTAL INPUT S WHILE LEN(S) IF NUM(S) THEN TOTAL += S ELSE DISPLAY @SYS.BELL : REPEAT END
This program reads numbers from the keyboard and displays a running total until a blank line is entered. |