Chapter
51
Basic
Concepts
Manipulating Data
BASIC uses expressions
as
a
way
to
manipulate data. An expres-
sion
is
2
or
more pieces of data connected by operators.
An
operator
is
a symbol
or
a
word that signifies some action
to
be performed on the specified data. Each data item is called an
operand.
An expression might look like this:
operand1 operator
operand2
6
+
2
A few operators allow only one operand, for example
operator operand
-
5
Expressions must be used in a BASIC statement, such as:
A=6+2
PRINT
-5
BASIC has four types of operators:
Arithmetic
String
Relational
Logical
used for numeric data only.
used
for
string data only.
used for both numeric and string data.
used for numeric data only.
Arithmetic Operators
Arithmetic operators perform operations on numeric data. Both
operands must be numeric. When BASIC evaluates the expres-
sion, all operands are converted
to
the same degree
of
precision,
that of the most precise operand. The result
of
the arithmetic
op-
eration is also returned
to
this degree of precision.
The arithmetic operators are listed below. They are in order
of
precedence, that is, the order in which BASIC executes them if
1
or
more operators are in the same statement.
Exponentiation. Calculates the power
of
a
number. For example, 2^3 is
8
(2
to
the power
of
3
is the same as 2*2*2).
Negation
or
Unary Minus. Makes a number
negative.
For
example, -10 is “negative ten.”
A
51