Each programming language has various types of elements, which are essential to write a programs. QBASIC also consists such programming elements and proper rules for preparing effective programs. The following are the basic Elements of QBAIC Programming language.

  • Character Set
  • Variables
  • Constants
  • Operators
  • Keywords

Character Sets

The QBASIC Character Set consists of letters, numbers and special characters.

  1. Letters : A – Z or a – z
  2. Digits : 0, 1, 2, 3, …… 9
  3. Special Characters : +, -, *, , =, /, ;, “, ^, $, #, !, %, ? etc.

Variables

Variable is a data item which can store some values such as numbers or string. It is a name of storage location in the computer’s memory, in which we can store different values. It may change during the program execution time. There are two types of variables. They are:

A) Numeric Variable

The variable which is used to store numeric data is called numeric variable. Numeric data means numbers that can perform mathematical calculations. For example x = 5, here the variable x is stores the numeric value 5.

Example :

CLS
x = 5
y = 6
z = x + y
PRINT z
END

OUTPUT

11

B) String Variable

A variable that stores string data is called string variable. String is the collection of letters, numbers and special symbols enclosed in double quotes. String data means alphanumeric values that cannot perform mathematical calculations. The string variable name must begin with alphabets and should always end with a $ sign. For example name$ = “Technical School”, here the variable name$ stores the string value “Technical School”.

Example:

CLS
name$ = “Welcome to Technical School”
PRINT name$
END

OUTPUT

Welcome to Technical School

Constants

Constants are the fixed value which remain unchanged during the program execution time. There are two types of constants. They are:

A) Numeric Constants

Numeric constants includes positive or negative number values. These values can be used in mathematical calculations such as addition, subtraction, multiplication and division. For example x = 5, here 5 is a numeric constants. Some valid numeric constants are 5, 10.5, -34 etc.

B) String Constants

A string constant is a set of alphanumeric characters, which are enclosed within double quotation marks. For example name$ = “Technical School”. Here “Technical School” is a string constants. Some example of string constants are: “14 years”, “3 boyes”, “Nepal” etc.

Operators

Operators are the symbols, which refers to a specific operation. In the program operators are used to perform arithmetic and logical operations. For e.g ‘+’ is a operator which adds any two numbers. The operator works between two or more than two values and gives result.

The following types of operators are used in QBASIC.

  1. Arithmetic Operators
  2. Relational or comparison Operators
  3. Logical Operators
  4. String Operators

1.  Arithmetic Operators

The operators which are used to perform different types of mathematical calculations such as addition, subtraction, multiplication and division are known as arithmetic operator.

Operator Meaning
+ Addition
Subtraction
* Multiplication
/ Division
\ integer Division : 10 \ 4 = 2
MOD Modulus Division : 10 MOD 3 = 1
^ Exponent : 5 ^ 3 = 125

2.  Relational or Comparison Operators

The operators which are used to compare two values are called relational or comparison operators. The relational operators used in QBASIC are as follows.

Operator Symbol Relation
= Equal to
Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

3.  Logical Operator

The operators which are used to combine two or more relational expressions are called logical operators. It gives two logical value “True” or “False”. The logical operators used in QBASIC are as follows:

AND
OR
NOT

AND

AND operator gives ‘true’ result, only when all the input are ‘true’. The AND truth table is given below.

X Y Result
T T T
T F F
F T F
F F F

OR
OR operator gives ‘true’,when any one or all inputs are ‘true’. The OR truth table is given below.

X Y Result
T T T
T F T
F T T
F F F

NOT

NOT Operators on one operand and return ‘True’ if the logical operation returns ‘False’. The NOT truth table is given below.

X Result
T F
F T

Keywords

Keywords are the collection of commands, statements or functions which are used to accomplish the particular job. Some example of QBASIC keywords are CLA, INPUT, PRINT, KILL, END, FOR, DO etc.

String Operator

String operator joins two or more strings. This process es called concatenation. The ‘+’ sign is used as the String operator.

Example:

CLS
x$ = “Technical ”
y$ = “School”
PRINT x$ + y$
END

Output

Technical School

 

<< Table of Content >>