In this Article, You Will Get Basic Guide about QBASIC Including:-



  • Some Versions of Qbasic

  • Basic Elements of QBASIC

  • operator and Constant of QBASIC

  • Many more

So, if you want to learn about QBASIC this Article is for You!

Let’s Jump Right in,



   In This Lesson, I've Used QB64 You can Download from here.


 What is QBASIC


Beginners' All-Purpose symbolic Instruction Code ( BASIC) is one of the easiest high-level Programming Languages.

It allows the usage of English-like language and uses of mathematical notation.

It was developed in 1964 at Dartmouth college, U.S.A by professors John Kemeny and Thomas Kurtz.

Originally, it was developed as an interactive language for mainframes. Since,

its Development BASIC has undergone many modifications and improvements and now many versions of BASIC are available,

Each version having some extra functionality/Feature.

Some versions of BASIC are:

  • Visual Basic

QBASIC is a high-level computer Language Published by Microsoft.

QBASIC environment includes:

  • Multi-file and Multi-window editing
  •  full debugging Facilities
  • pull-down menus
  • syntax-checking editor
  • simple yet powerful menu structure

Once you are in the QBASIC Environment you can edit, run, debug, and rerun the program without switching programs.

Elements of QBASIC



The important elements of the QBASIC program are:

  • QBASIC character set
  • Variable
  • Constant
  • Operator and expression
  • Keywords ( Reserved Words )

Character Set


The QBASIC character set is a set of symbols used to frame the various components of a program.

The character set consists of digits, letters, and special characters that are valid in QBASIC.

Character Sets of QBASIC

Alphabets : 

 A to Z ( Small and Captial Letters 

Numbers : 

0 to 9

Special Characters :

; = + - * / ^ () % $ # ! , . ' ": & ? <> \ -


Variables are Programmer-defined areas in The numeric’s memory for storing data.


The data stored in a variable can change during the execution of the program as per the requirements and functionality of your program.

However, the name of the variable in a program remains unchanged.

This is the reason why variables are very easy to use.

The variables are of two types:

  • Numeric variable
  • String variable

Depending on the kind of data item they represent.

Numeric variable


The numeric variable has a number as its value. It must begin with an alphabet and the remaining characters, if used, may be alphabets or digits or both. 

Some of the valid numeric variables are:

  • a1
  • area
  • weeks7

String variable

The string variable has a string of characters or alphanumeric as its value.

It must begin with an alphabet and end with a dollar sign ($). 

Mathematical calculations cannot be performed Using string variables.

Some of the valid string variables are:

  • A$
  • t1$


Constant is a data item whose value doesn't change during the execution of a Program. It is also called literal.

Constant are of two Types:

  • Numeric constant
  • String constant

Numeric constant

A numeric constant is a sequence of positive or negative numbers on which mathematical operations can be performed.

They are entered in the same form. Commas are not allowed in a numeric constant.

Some of the valid numeric constants are:

  • 26
  • -18
  • +84
  • 40

String Constant

String Constant is a sequence of characters that may include numbers, letters, and certain special characters enclosed in quotation marks.

It is used to represent non-numeric Information such as names, addresses, class, sections, and many more.




Types of Constants


integer constant

" Today we sold"

string constant

" Bushels " 

String Constant

" of apples " 

String Constant


Operator and Expression



Operators are the symbols representing the operations they perform.

The operator helps to convert one or more values into a single value.


The values on which the operators work are referred to as operands.

A combination of an operator and its operands is referred to as an expression.

Operators are used in Expressions to store or return a value. Look at the following statement:

sum = 30+7

Since 30+7 has a value, it is an expression.  Its value 37, is stored in the variable sum.

Expressions do not have to be in the form of mathematical operations.

In the following statement, 4 is an expression.

number = 4

QBASIC offers different classes of operators:

  • arithmetic
  •  relational
  • logical
  •  string operators.

Arithmetic operators

Arithmetic operators are the operators that operate on numeric constants and variables.

They are used to perform various mathematical operations.

The general format of the arithmetic operator is:

operand1 arithmetic_operator operand2




Raise a Number to the power of another

x = y^z


Multiplies the Operands

x = y * z

Divides the left operand by the right operand

 x = y/z


Divides the left operand by the right operand and returns the remainder

x = y mod z


Operations within parenthesis are performed first.

Inside the parenthesis, the usual order of precedence is maintained.

It is always a good idea to put parentheses around the expression.

Some advanced operators will produce unexpected results otherwise.

Some Algebric Expression and Their CounterParts:

Algebric Expression

BASIC Expression

5a + 6b  


(3a - 4b)/c

(3*a  - 4*b)/c



Relational operators


Relational operators are used to comparing two values of the same type, either numeric or both string.


The general format is:


operand1 relational_operator operand2

The relational operators supported by QBASIC are:




Compares Two numbers and Evalutes

 A = B


Compares Two numbers and evalutes them to true if the left operand is less than the right Operand

 A < B


Compares two numbers and evalutes them to true if the left operand is greater than the right operand

A > B

< =

Compares two numbers and evalutes them to true if the left operand is less than or equal to  the right operand

A < = B

> =

Compares two numbers and evalutes them to true if the left operand is greater than or equal to  the right operand

A > = B


Compares two numbers and evalutes them to true if the operands are not equal 

A <> B

Logical operators

Logical operators are used to connecting two or more relational expressions to evaluate a single value as True or False.

The general format is:

Operand1 logical_operator operand2





Evalutes to true when both conditions are true


Characteristic 2

Characteristic 2

Characteristic 2

Characteristic 3

Characteristic 3

Characteristic 3

Characteristic 4

Characteristic 4

Characteristic 4

Concatenation operators

An expression involving string variables and constants are called string expression.

Concatenation operators connect multiple strings into a single string.

QBASIC uses the plus sign (+) as a string concatenation operator.


B$ = "The Best Blog in The world."
C$ = A$ + "is" + B$ ' Plus sign connects Multiple strings.


PENTLI is The Best Blog in the world.



Keywords are the words that convey a special meaning to the language.


These are reserved for special purposes and must not be used as normal identifier names.

Some of the QBASIC keywords are:

  • REM

  • CLS


  • LET


  • END

QBASIC Statements


QBASIC Statement is a meaningful expression or an instruction in a source language.

Each statement is followed by a RETURN key.

These statements are first stored in the memory and executed only when the command RUN is given.

It is either executable or non-executable. Executable Statements are Program instructions that tell BASIC what to do during the execution of a Program.

Non-executable statements do not cause any program action. 

The statements can be divided into four categories:

  • Declaration statement

  • Assignment statement

  • Input/output statement

  • Control statement

REM Statement

The REM Statement is a non-executable statement.

 It is used to include explanatory remarks to be inserted in a program, which are very helpful to explain what a program does and what specific lines of code do.

This statement can be used anywhere and any number of times in a program. 

They are intended for people who may be reading the source code.


This statement can be used anywhere and any number of times in a Program.

An apostrophe ( ' ) may be used instead of REM. The general format of the REM Statement is:

REM<remark> or '<remark>'



REM " This is a Basic Program that adds two number"

INPUT " Enter a Number:"; a$

INPUT " Enter Second Number"; b$

LET total = a$ + b$

PRINT " The Total Number is:"; total


CLS Statement

CLS Statement is used to clear the output screen. It makes the screen completely blank.

This command is generally given before the start of any program so that there is a fresh screen and any leftover from the previous Program is cleared completely.

The general format of the CLS Statement is:



LET statement

LET statement is an assignment statement used to assign the value of an expression to a variable.


LET is an optional keyword I .e.. the equal sign is sufficient when assigning an expression to a variable name.

The type of expression ( string or numeric ) must be the same as the type of the variable.

Otherwise, a "Type mismatch" error will occur. The general format of the LET statement is:

LET<variable> = <expression>

CLS ' cleans the screen'

REM " calculate the area of Rectangle "

LET length = 30

LET breadth = 20

LET area = length * breadth ' calculate the area of Rectangle '

PRINT " The area of Rectangle is"; area


INPUT Statement

The INPUT statement is used to accept input from the keyword during Program execution.


It facilities the use of the same program for various sets of data to obtain different results in different executions.

During the execution of a program, when the control comes to INPUT STATEMENT, a question mark appears on the screen and waits for data to be input on the keyboard.

Unless a response is entered, the control does not move to the next line. 

The type of data item in the response ( numeric or string ) must agree with the type specified by variable and the number of data items supplied by the user must be the same as the number of variables listed in the Statement.

The general format of INPUT Statement is:

INPUT ["definer";|,] list of variables

INPUT " Enter the side of a cube"; a
volume = a ^ 3
tsa = 6 * a ^ 2
PRINT " Volume of a cube"; volume
PRINT " Total surface area"; tsa

PRINT statement

PRINT Statement is used to Display Data on screen. This statement will print constants, variables, or expressions.


A Question mark (?) May be used instead of the word PRINT.

Format of PRINT Statement is:

PRINT[ list of expressions] [ ,| ;]


? [list of expressions][, | ;]

PRINT Positions

BASIC divides the line into print zones of 14 spaces. 

The position of each item displayed on the screen is determined by the punctuation used to separate the items in the list.

The Separator and print position is described below:


Print Position




Side by Side

Space (s)

Immediately after The Last Value

TAB Function 

TAB Function is used to space to position n. It may be used only in PRINT, LPRINT, and PRINT# Statements.


Space 1 is the leftmost position, and the right-most position is the defined width.

If the current print position is already beyond space n, TAB goes to find a position on the next line.

If n is negative, it produces the same result as TAB(1).

If n is out of range, an overflow error occurs.

The general format of the TAB Function is:

TAB (n)

LOCATE Statement

LOCATE Statement is used to move the cursor to the specified position on the screen and determine the height of the cursor.

The General format of LOCATE Statement is:

LOCATE [row],[col],[cursor],[start][,stop]]]]

INPUT " Enter the Length of the room"; leng

INPUT " Enter the breadth of the room"; brea

INPUT " Enter the height of the room"; heig

INPUT " Enter the cost of painting per unit area"; cost

LET area = (2*(leng + brea)) * heig

LET total = cost * area

LOCATE 9,50: PRINT "Total cost of Painting the room is"; total


END Statement

END Statement denotes the end of the program. 


Once the program encounters the END Statement, the computer stops processing any further as it has reached the termination point.

It must be written as the last statement in every program.

The general format of END Statement:


What Does Branching Statement Do?

Branching Statement allows your program to transfer the control to some other specified Statement instead of the sequential execution.

There are two types of branching Statements:

  • Unconditional Branching

  • Conditional Branching

Unconditional Branching Statement

Unconditional Branching Statement is a statement that transfers the control unconditionally ( without testing any condition ) from one Statement to another Statement in a program.

GOTO Statement is the simplest unconditional Branching Statement.

GOTO Statement

GOTO Statement is used for the unconditional transfer of execution from one part of the program to the other.

It does not depend on any test of condition.


The general format of the GOTO Statement:

GOTO [line number | line label]

x = 1 

top: ' A label is a name followed by a colon.




GOTO top


The program evaluates the expression y=x*x repeatedly for x = 1,2,3…. The value of x is incremented at the fourth Line and then the control of execution comes to GOTO top,

It will be transferred to the label top. The control will never come to the END Statement.

So, it becomes an infinite loop

(i.e a never-ending loop).

To stop the execution of this program, press the CTRL + Pause Break key.

A line is an identifier followed by a colon that can be placed before any QBASIC Statement.

The line label has the following syntax: [label]:

Conditional Branching Statement

Conditional Branching Statement is a statement that allows the selective execution of Statements based on a particular condition.

It enables the computer to decide upon which of the several possible actions to take.

Based on a given condition a selected segment of the program is executed.

It depends upon whether the state of a particular condition is true or false.

A conditional Branching Statement is also called the decision-making Statement.

The conditional Branching Statement includes IF...THEN and SELECT CASE Statements.

IF...THEN Statement

The IF...THEN Statement is used for making decisions as well as comparisons.

It allows branching depending upon the value of an expression.

The Statement to be executed or ignored depends upon the condition.

The different forms of IF... THEN Statement is:

  • IF...THEN...ELSE Statement

  • IF...THEN Statement

  • IF..ELSEIF..ENDIF Statement

i. IF...THEN Statement


IF...THEN Statement is a conditional Branching Statement.

If the condition is true, the statement given next to THEN will be executed otherwise next executable Statement following IF...THEN Statement will be executed.

The general format of IF...THEN is:


dis = 0

INPUT " ENTER Quantity"; q

INPUT " Enter rate"; r

IF (q > 1000) THEN dis = 10

total = (q*r)-(q*r*dis/100)

PRINT "Total expenses = "; total



IF...THEN...ELSE STATEMENT is an extension of IF...THEN... Statement.

IF...THEN...ELSE Statement tests a particular condition and asks the computer true or false questions only.


If the condition is true, the computer will follow the command given after THEN.

If the condition is false, the computer will altogether ignore the command after THEN and moves to the ELSE part to execute the command stated there.




REM " This Program calculates tax of an employee "

INPUT " Enter The annual Salary of an employee "; sal

IF sal > 15000 THEN tax = 15/100* sal ELSE tax = 10/100* sal

PRINT "The total tax paid by an employee:::"; tax


iii. IF..ELSEIF..ENDIF Statement

The IF...ELSEIF...ENDIF Statement is a chain of IF Statements.

They perform their tests, one after the other until one of them is found to be true.

The conditions are evaluated from the top and if one of them is true, the corresponding block of statements is executed.

The executable Statements following the last ELSE Statement are executed if all the other conditions on the IF and ELSEIF lines are false.

The general format of IF...ELSEIF...ENDIF statement is:

IF [ condition ] THEN


ELSEIF [condition 2] THEN










t = 200*p


t = 300*p


t = 180*t


IF p >= 5 THEN d = 5 / 100 * t

f = t - d



What is A Looping Statement?

Loop is a control structure that causes a statement or group of Statements to repeat, based on a condition.

The repetition continues while the condition set for it remains true.

When the condition becomes false, the loop ends, and the control is passed to the statement, following the loop.

The looping statements allow flexibility to the programmer in controlling the number of times a specific instruction is to be repeated.

QBASIC supports the following looping statements:

  • FOR...NEXT


  • DO...LOOP

FOR... NEXT Statement

FOR...NEXT Statement is used to execute a series of instructions for a given number of times.


FOR Statement is placed at the beginning of the loop and NEXT Statement at the end.

The general format of FOR...NEXT Statement is:

FOR <counter variable>=x to y<STEP z>

                         <program Statements>

NEXT<counter variable>

In the FOR...NEXT Loop:

  • A counter variable is used to keep count of the number of times the loop is repeated.

  • The initial value (x) and final value (y) for the counter variable are given with the FOR Statement. The Statement clause may be included to increase or decrease the value of the counter variable by any number.

  • If the STEP clause is not included, the default value for STEP, i.e., 1 used. The STEP Statement may also have a negative Value if the initial value is greater than the final value.

Rules for FOR...NEXT Statement

The following rules must be kept in mind while constructing a FOR...NEXT loop:

The counter variable can appear in a statement inside a loop, but its value cannot be changed.

If the initial and final values of the counter variables are equal and the step value is non-zero, then the loop is executed once.

The loop will not be executed when:

  1. The initial and final value of the counter variables are equal and the step value is zero.
  2. The final value of the counter variable is less than the initial value and the step value is positive.

  3. The final value of the counter variable is greater than the initial value and the step value is negative

WHILE...WEND Statement

WHILE...WEND Statement is an entry-controlled loop. 

It is used to execute a series of statements as long as a given condition is true.


If the condition is true, all the statements are executed and when the WEND Statement is reached, control is returned to the WHILE Statement which evaluates the condition again.

If the condition is still true, the process js repeated.

If the condition is false, the program execution jumps to the Statement following the WEND Statement.

The general format of WHILE...WEND Statement is:

WHILE [ expression ]

                  < program Statements >



Following rules must be kept in mind while constructing a WHILE...WEND loop:

  • All Variables in the test condition of the WHILE construct must be initialized at some point before the WHILE loop is reached.

  • The body of the loop must do something to change the value of the variables used in the condition being tested. Otherwise, the condition will remain true, and the loop will never terminate. This situation is known as an infinite loop.

  • To prevent infinite loops, a statement must be included in the WHILE...WEND loop that modifies the variable in the expression.

DO...LOOP Statement

DO...LOOP Statement causes a set of program statements to execute repeatedly until certain conditions are met as certain conditions are true.

There are two variations of DO...LOOP Statement and both use the same basic model.

A loop can execute either while the condition is true or until the condition becomes true.

These two variations use the keywords WHILE and UNTIL to Specify how long the Statements are executed.

The syntax for DO...LOOP Statement can either of two forms.

syntax 1


              <statement block>
LOOP WHILE\UNTIL <boolean expression>

syntax 2

DO WHILE\UNTIL <boolean expression>

                              <statement block>


n = 5 

i = 1


PRINT n; “x”;i; “=”; n * 1

i = i + 1

LOOP WHILE i <= 100


Nested Looping

A loop structure placed inside another looping structure is said to be a nested loop.

When a loop is defined inside another loop, the inner loop operates as many times for all the values of the outer loop.

The rules for the Formation of a nested loop are:

  • An outer loop and inner loop cannot have the same control variable.

  • The inner loop must be completely nested inside the body of the outer loop.

  • The inner loop must terminate before the outer loop.

  • The outer loop opens first but closes last.

  • Loops must never cross each other.


FOR outloop = 1 TO 5

FOR inloop = 1 TO outlook

PRINT inloop;






I hope you enjoyed my new Article about QBASIC.

Now I’d like to hear from you: 

 Did you already know about QBASIC?

 If so, what’s your favorite feature About QBASIC?

 Let me know by leaving a comment below right now.


Recommended Resources

Learn About QBASIC ( Beginner's Guide)

QBASIC Programming Series ( Youtube Playlist )

Our Author

Guinness Publication Pvt. Ltd

kathmandu, Nepal

facebook: https://bit.ly/3ewYfoo

Email: [email protected]


What is QBASIC?

Beginners' All-Purpose symbolic Instruction Code ( BASIC) is one of the easiest high-level Programming Languages.

It allows the usage of English-like language and uses of mathematical notation.

It was developed in 1964 at Dartmouth college, U.S.A by professors John Kemeny and Thomas Kurtz.

What are the Elements of QBASIC?

The important elements of the QBASIC program are:

  • QBASIC character set
  • Variable
  • Constant
  • Operator and expression
  • Keywords ( Reserved Words )
This post was last updated on

2 thoughts on “Definitive Guide: What is QBASIC? (Unforgettable) in 2020”

Leave a Comment