Key Basic Statements
Key Basic Statements
The keywords or the reserved words are the tools that we use in writing
BASIC programs. They are instructions that are carried out by the program
translator, i.e., the compiler and the interpreter. They include:
PRINT,
CLS,
REM,
READ
GOTO,
DATA
FOR … NEXT,
IF … THEN …ELSE,
LIST
LOAD / (OPEN),
END,
STOP
1. Remark Statement (REM): a remark statement does not affect the
program in terms of instruction or command line. It is used in explaining
what the program is all about.
Example,
10 REM. Program to calculate average of numbers. This statement will
appear as comment on the screen.
2. Assignment Statement: This keyword is used in assigning values to
variables, e.g. READ, DATA, LET, INPUT
a. READ statement: This is a statement used in giving values to variables.
Usually READ statement has DATA statement with it.
Examples,
I 10 READ I,M,N
20 DATA 5,7,9
II 10 READ A,B,C
20 DATA 1,2,3
B. DATA statement: This statement is used in attaching strings of fixed
characters and numeric data in BASIC. A DATA statement can have one piece
of data or many. Either of these is called DATA element. DATA elements are
separated by commas (,).
Examples,
I. 10 READ A,B,C,D
20 DATA 6,7,15,10
30 PRINT “SUM” = A+B+C+D
40 RUN
SUM =38
II. 10 REM PROGRAM TO SUM NUMBERS
20 READ X,Y,Z
30 DATA 15,10,20
40 PRINT “SUM” = X+Y+Z
SUM = 45
3. PROGRAM TERMINATOR
These keywords are used to terminate the program, e.g. STOP AND END
a) STOP statement: This statement is used to terminate a program.
b) END statement: This statement is used to terminate a program.
Example,
10 REM
20 GOTO 50 (The program moves to line 50)
30 READ A, B ,C, D
40 PRINT “SUM” = A+B+C+D
50 STOP
4. OUTPUT STATEMENT.
This keyword is reversed to display output from the computer, e.g. PRINT
a) PRINT statement: This statement is used to transmit or display output data
from the computer. The PRINT statement is usually followed by a list of items
to be displayed and each item is separated by a comma (,) or semi-colon (;)
Examples are:
I) 10 PRINT A, B, C
20 PRINT “X” =; “Y” = Y
This statement will cause the monitor to display whatever is stored in the
non-numeric variables ABC and whatever is stored in X and Y.
II) PRINT (2*4)/2
The monitor will display 60
III) 5 LET A = 50
10 LET B = 10
15 LET C = A + B
20 PRINT C
The monitor will display 60
ASSESSMENT
OBSERVE THE PROGRAM FLOW BELOW
200 LIST:
300 PROD
400 READ A, B, C
500 DATA 3, 4, 9
800 END
Note: The line number does not affect the program and sometimes not
necessary in some advanced IDE compiler
ASSIGNMENT
With the assessment above, on your own write a basic program to SUM three
numbers and output the result. Using SH1 as the variable to hold the value
to be printed.
To be submitted tomorrow: 4th January 2025