What is QBASIC? : The Definitive Guide in 2021
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,
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
- Operator and expression
- Keywords ( Reserved Words )
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.
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.
Also Read: What is Information Technology(Including amazing Skill-sets You Must Have) in 2020.
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:
- string 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
- 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:
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:
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
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.
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:
Also Read: Develop Algorithm - Here is what you can accomplish with them
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
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>'
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 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>
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
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][, | ;]
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:
TAB Function is used to space to position n. It may be used only in PRINT, LPRINT 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:
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:
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 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]
What Does Branching Statement Do?
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 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>
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:
- The initial and final value of the counter variables are equal and the step value is zero.
- The final value of the counter variable is less than the initial value and the step value is positive.
- The final value of the counter variable is greater than the initial value and the step value is negative
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 >
Rules for a WHILE...WEND STATEMENT.
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 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.
LOOP WHILE\UNTIL <boolean expression>
DO WHILE\UNTIL <boolean expression>
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.
A Simple QBASIC QUIZ:
1. What does the "Q" in QBasic stand for?
2. What is the correct way of displaying something on the screen?
3. Which of these commands do you use to finish a program?
4. When was Qbasic created?
5. A GOTO statement can be used to:
Reveal the Answers
Now It's Your Turn
I hope you enjoyed my new Article about what is QBASIC: The Definitive Guide.
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.