Introduction to Basic
Introduction to Basic
Alphabets A-Z
Numeric 0-9
THE BASIC CHARACTER SET
6. PRINT C
7. END
1. READ A,B,C
2. LET Q= A+B-C
3. LET P=Q*A
4. DATA 10,20,30
5. PRINT Q,P
6. END.
REM STATEMENTS
REPETITION
A program may be design to perform more than one task. An example
is calculating the GPA of each student studying CSC 103. In order to
calculate the GPA for more than one student, we would have to execute
the program for more than once. This process will have to be repeated
again and again for a specific number of times. You must know how to
program a loop in order to repeat the calculations. You also know how
to exit from a loop. You must lean conditions in order to loop and exit
from loom.
CONDITIONS
One way to create a loop in BASIC is to use the do statement and the
loop statement. The DO statement indicate the top/start of the loop
and the loop statement indicate the bottom/end of the loop.
The DO and LOOP statements can be written in several ways as
illustrated below.
DO WHILE LOOPS
Syntax
DO WHILE condition
THE DO…..LOOP STATEMENT
Statement(s)
LOOP
DO UNTIL LOOPS
Syntax
DO UNTIL condition
Statement(s)
LOOP
THE FOR…..NEXT LOOP
There may be the need for programs to give more than one output base on
some conditions that change in run-time. In such cases conditional
statements are used. Some of the common conditions are discussed below:
The If statement
IF condition THEN
Statement(s) to be executed if condition is true
Else statement(s) to be executed if condition is false
END IF