How to Construct an Expression
Understanding
how
to constructan expression will help you put together
powerful statements- instead
of
using many short ones. In this section we will
discuss the two kinds
of
expressions you may construct:
• Simple
• Complex
as well as how to constructa function.
As we have stated before, an expression is actually data. This is because once
BASIC performs all the operations, it returns one data item. An expression may be
string
or
numeric.
It
may becomposed of:
• Constants
• Variables
• Operators
•
Function~
Expressions may
be
eithersimple
or
complex:
A
simple expression consists
of
a single term: a constant, variable
or
function.
If
it is a numeric term, itmay be preceded by an optional +
or
- sign.
Forexample:
+A
3.3
-5
SQR(8)
are all simple numeric expressions, since they only consist
of
one numeric term.
A$
STRING$ (20, A$)
"WORD"
"M"
FUNCTION
VARIABLE
are all simple string expressions since they only consist
of
one string term.
Here's
how asimpleexpressionis formed:
...----------,
+ G CONSTANT
'-.../
A complexexpression consists
of
two or more terms (simple expressions)
combinedby operators. Forexample:
A-1
1=1
AANDB
ABS
(B)
+LOG(2)
are all examples
of
complexnumeric expressions. (Notice thatyou can use the
relational expression
(1 =
1)
and the logical expression (5 AND
3)
as a complex
numeric expression sinceboth actually return numeric data.)
A$+B$
"Z"+Z$
STRING$(1
0,
"A") +
"M"
are all examples
of
complexstring expressions.
1/29