Subject: Computer
QBASIC can handle arithmetic expression involving the five arithmetic operators + (addition), - (subtraction), * (multiplication, / (division) and ^ (exponentiation).
The hierarchy of operations is as follows:
Thus, in a particular arithmetic expression, the order of execution is as per this hierarchy, i.e. all exponential operations are performed first, and then multiplication/division and the addition/subtraction operations are the last to be carried out. Note that within a particular hierarchical group. Within a particular hierarchical group, the operations are executed from left to right and by use of parentheses normal hierarchy of operations can be altered.
In addition to this hierarchy of operations, the following rules must be kept in mind in arithmetic expression:
Let us take an example where we give QBASIC equivalents of a few algebraic expressions.
Algebraic Expression | QBASIC Equivalent |
-2A+B | -2*A+B |
-A+B/C+D | -(A+B)/(C+D) |
-A(B+C) | -A*(B+C) |
-B2-4AC | -B^2-4*A*C |
A relational expression is formed by using any of the following relational operators:
Relational Operator | Meaning |
= | Equal to |
> | Greater than |
< | Less than |
<= | Less than or equal to |
>= | Greater than or equal to |
<> | Not equal to |
In the execution of programs, it is sometimes desired to compare two numerical quantities (or sometimes string quantities) and take decisions on achieving certain conditions. For example, we may be interested to check the number of repetitive calculations performed or to find out whether the denominator of an arithmetic expression has become zero or if a particular quantity is negative, and so on. Expressions written to compare two quantities using certain rational operators are known as relational expressions.
When expressions are used on either side of relational operators, the expressions will be evaluated first and then the results of expressions compared. This means that relational operators come last in hierarchy of operators.
QBASIC, also supports logical operators to perform logical operation on numerical values. Logical operators are used to connect two or more relations and return a TRUE or FALSE value to be used in a decision.
The common logical operators are:
For example, the expression A>50 AND B>150 is TRUE when A is more than 50 and at the same time B is more than 150.
Logical operators return results as indicated in the following tables. T indicates a TRUE and F indicates FALSE. X and Y are relational expressions.
AND Operator
X | Y | X AND Y |
T | T | T |
T | F | F |
F | T | F |
F | F | T |
OR Operator
X | Y | X OR Y |
T | T | T |
T | F | T |
F | T | T |
F | F | F |
NOT Operator
X | NOT X |
T | F |
F | T |
Specific words which are not applicable to use as a variable on computer program are Keywords. These are also called reserved words. For example INPUT, GOTO, PRINT etc.
A set of rules and regulation that must be followed to construct the program structure is called Syntax. It is one type of grammar to use the command and statement of computer.
QBASIC can handle arithmetic expression involving the five arithmetic operators + (addition), - (subtraction), * (multiplication, / (division) and ^ (exponentiation). The hierarchy of operations is as follows:
Logical Operator, Meaning
=, Equal to
> , Greater than
< , Less than
<=, Less than or equal to
>=, Greater than or equal to
<> , Not equal to
Logical operators are used to connect two or more relations and return a TRUE or FALSE value to be used in a decision.
The common logical operators are:
© 2019-20 Kullabs. All Rights Reserved.