UC2 Week 7 Topic: Basic Programming I Sub-Topic: Introduction To BASIC Programming
UC2 Week 7 Topic: Basic Programming I Sub-Topic: Introduction To BASIC Programming
BASIC VARIABLES
A variable is a quantity that changes during the execution of a program. It can also be defined as a name
that is used to represent some storage location.
Types of Variables
1. Numeric Variables
2. String Variables
CONSTANTS
A constant is data that remains the same as the program runs (executes).
BASIC allows two types of constants:
1. Numeric constant.
2. Alpha-Numeric or string constant.
GO TO - changes the sequence order of a program. It transfers program control from a line number to a
given line number. E.g.
10 REM
20 READ $NAME, AGE, SCORE
30 INPUT “Thomas”, 10, 98
40 IF $NAME = “Tom”
50 GOTO 90
60 PRINT “My name is Thomas, I am 10 years old and I scored 98”
70 GOTO 90
80 PRINT “My name is Tom, I am 10 years old and I scored 98”
90 END
IF-THEN - conditional statement that decides if the program will change. It is used to execute a single
statement on a conditional basis. E.g.
10 IF X < 0 THEN
20 PRINT X
IF-THEN - ELSE – This is a conditional statement used to execute multiple conditional statement. It
permits one or two different groups of statements to be executed depending on the logical test outcome.
The syntax for IF – THEN – ELSE is:
IF logical expression THEN
Executable statement
ELSE
Executable statement
END IF
FOR NEXT: This is an unconditional statement that is used to carryout unconditional looping. The
format is:
FOR I = 1 TO 10
PRINT I
NEXT I
STOP or END – The STOP statement is used to stops the execution of a program at any point in the
program. The END statement indicates the actual end of a program. The STOP statement can appear
many times but the END statement can only appear once at the end of the program. E.g.
90 END
INPUT - tells the computer that information is needed to be typed into the terminal for interaction with
the program. It is used to enter data into our program during program execution. E.g.
80 INPUT A, B, C
90 INPUT N$, M$, Factor
Expressions and Operators
In programming, an expression can be defined as the combination of operand and operator which is to be
evaluated to produce answer. Operands are the data items involved in an expression. Operators determine
the action to be carried out on the operand in the expression. For instance in the statement: LET C = A +
B, A and B are the operands while “+” is the operator.
There are three major types of expression in BASIC. They are:
i. Arithmetic expression
ii. Relational Expression
iii. Logical expression
Arithmetic Expression and Arithmetical Operator
BASIC arithmetic expression is used to represent mathematical formulae in BASIC programming. Below
is a list of BASIC arithmetic operators:
Arithmetic Operator
/ Slash Division
* Asterisk Multiplication
+ Plus Addition
- Minus Subtraction
Arithmetic Expression
lbc L*B*C
ut+1/2at^2 U*T+1/2*A*T^2
PTR/100 P*T*R/100
Relational Expression
Relational Expression is used for comparison of two or more data items. BASIC relational operators are
listed below:
SYMBOL NAME
= Equal to
Logical Expression
Logical expression involve is an expression involving two or more relational repression joined by logical
expression. BASIC logical operators are:
i. AND
ii. NOT
iii. OR