Friday, December 21

BASIC Expression

A BASIC expression is a sequence of BASIC variables and/ or BASIC constants, separated by operators, which can be evaluated to give a result. 
A BASIC expression may be simply a string or numeric constant, a variable, or may combine constants and variables to produce a single value.
There are three different kinds of BASIC  expressions. They are :
1. Arithmetic expression
2. String expression
3. Relational expression 

1. Arithmetic expression
An arithmetic expression is a combination or set of operations, constants and variables.
When an arithmetic expression is formed using only valid BASIC operations, valid BASIC constants and valid BASIC variable names such expression is known as BASIC arithmetic expression.
Consider an arithmetic expression,
b2-4ac  …………….(i)
The BASIC  arithmetic expression equivalent to this expression will be
B^2 -4* A * C …………(ii)
This expression has three real variables A, B and C. 

2. String expression
The expression written to deal with two or more string values using certain string operators is called String expressions.

 3. Relational and logical expression
The expression written to compare two or more numeric or string values using certain logical are called logical or relational expressions.
A relational expression is an expression that is made up of logical and relational operators and conditions.
The relational or logical operator can be written in the form.
<Condition I>          <Logical operator>          <Condition- II>.............(i)
Where, Condition is of the form.
<Expression I>       <relational operator>       <expression- II>
Where,
Expression  :         arithmetic or string expression
Such expression can be made up of arithmetic or string operators and constants or variables.
Example 10 
Examples of Valid and Invalid relational expressions
Table C 2. 13 String variables
      
Valid
Relational expression
Invalid Relational expression
Expression
Invalid Reason
(X=Y) OR ( X<Y)







(N$=”A)” OR ( N $= “B”)
(N$=”A”) AND (N$= “B”)
(X=A $) OR (Y=5)








(X$=”A’)) OR (Y$=”B” )
Illegal comparison between numeric and string variables i.e. (X= A$)






Closing bracket without opening bracket i.e. (X$=”A”)

These relational and logical expressions are helpful in the comparison of two or more numeric or string quantities to arrive at decision. These expressions take one of the two values :
Yes or No
True or False   

No comments:

Post a Comment