CHAPTER 2 INTRODUCTION TO BASIC
Fundamental Concepts and Language Structure
BASIC is different from other programming languages in its concern for
the inexperienced user. Although it is a general-purpose programming
language, it is designed primarily to be easy to learn, easy to use, and easy
to remember. BASIC is oriented toward, but not restricted to, interactive
use.
Its statement structure is kept simple, and special rules are kept to a
minimum.
A BASIC program is meant to be simple so that even a novice is able to
deter-mine
what the program is expected to do on the basis of examination. Only
a little knowledge of BASIC is required to solve simple problems.
Simple BASIC programs can be used much like a small calculator. You
might want to ask the computer to multiply 4 times 25 and print the results.
The following example shows you how to accomplish this:
You keyed three lines into the computer. In the first line, line number 10,
you told the computer to calculate 4 times 25 and print the answer (* in
BASIC
means multiply). In the second line, line number 20, you told the computer
there were no more instructions in the program. The last command you gave
the computer was
RUN, a
system command which tells the computer to execute the instructions and give the results. The computer multiplied 4
times 25 and gave the answer, which is 100.
As simple as it may seem, this is a computer program. The same function
which took only one statement in BASIC, would take several lines of coding
in other high-level programming languages such as COBOL or FORTRAN.
STATEMENT STRUCTURE
The instructions which are preceded by line numbers are called statements.
A complete set of statements to solve a problem is called a program. The very
last statement in each program must be the
END
statement.
Program statements in the BASIC language can be constructed in free form.
The various parts must all appear, however, and be given in a definite order,
as shown below:
STATEMENT NUMBER.(Frequently referred to as line number). This
number has two vital functions: (1) to identify the statement itself
(statement
label); and (2) to indicate to the BASIC compiler (interpreter) where you
want
this statement placed in the program sequence. The statement number must
be an integer (a whole numberno decimal parts or fractions). For the
pur-pose
of this text, the range for statement numbers is from 1 to 99999. However,
the number of digits may vary depending on the computer you are using. Table
2-1 shows examples of statements with valid and invalid statement numbers.
Table 2-1.BASIC Statement Numbers
BASIC LANGUAGE KEYWORD.Keywords are used to tell the computer
what function is to be performed by this statement. For example, LET,
PRINT, INPUT, and END as shown in Table 2-1. These and other keywords
will be introduced and discussed as appropriate throughout the remaining chapters. The spelling of each keyword must be exact, or the compiler
(interpreter)
will tell you this is an invalid statement.
DESCRIPTIVE INFORMATION.This information completes the
description of the function to be performed and varies with the keyword used.
See the first three examples in Table 2-1. There area few instances where no
additional information is required or allowed. See the last example in Table
2-1.
In order to write these statements, you must first know the syntax; that
is, the characters and symbols used to construct the statements, as well as
the rules, conventions, and special features of the language. This includes
the
character set and the methods used to represent numbers and predefined
functions.
|