Arithmetic, Relational or Logical Expression

Subject: Computer

Find Your Query

Overview

Logical operators are used to connect two or more relations and return a TRUE or FALSE value to be used in a decision. This note contains further elaboration on arithmetic, relational or logical expression.
Arithmetic, Relational or Logical Expression

Arithmetic Expressions

QBASIC can handle arithmetic expression involving the five arithmetic operators + (addition), - (subtraction), * (multiplication, / (division) and ^ (exponentiation).

The hierarchy of operations is as follows:

  • Exponential
  • Multiplication and division
  • Addition and subtraction

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:

  • Two operations must not appear together. For example, C+-D, A/-C, etc are not permitted.
  • String constants and string variables should not be used in arithmetic expressions. For example P+P$ is wrong.
  • When brackets are used, they must be used in pairs, i.e. every left bracket must be matched with a right bracket.
  • Denominator of an expression should not be zero.
  • Within a given pair of parentheses, the natural hierarchy of operations will apply.

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

Relational or Logical Expressions

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.

Logical 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:

  • AND Conjunction
  • OR Disjunction
  • NOT Logical Negation

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

Keywords

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.

Syntax

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.

Things to remember
  • Logical operators are used to connect two or more relations and return a TRUE or FALSE value to be used in a decision.
  • Specific words which are not applicable to use as a variable on computer program are Keywords.
  • A set of rules and regulation that must be followed to construct the program structure is called Syntax.
  • It includes every relationship which established among the people.
  • There can be more than one community in a society. Community smaller than society.
  • It is a network of social relationships which cannot see or touched.
  • common interests and common objectives are not necessary for society.
Videos for Arithmetic, Relational or Logical Expression
Arithmetic Expression
Boolean Techniques - QB64
Operator and Expressions
Relational & Logical Operators
Relational and Logical Operators and Conditions
Questions and Answers

QBASIC can handle arithmetic expression involving the five arithmetic operators + (addition), - (subtraction), * (multiplication, / (division) and ^ (exponentiation). The hierarchy of operations is as follows:

  • Exponential
  • Multiplication and division
  • Addition and subtraction

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:

  • AND Conjunction
  • OR Disjunction
  • NOT Logical Negation
Quiz

© 2019-20 Kullabs. All Rights Reserved.