Keywords in qbasic

Codynn
5 Min Read

Keywords are the reserved words that instruct the computer to perform certain actions. Every programming language has its own keywords. In the same way, QBASIC also has its own keywords. Some of the examples of QBASIC keywords are INPUT, CLS, PRINT, etc.

NOTE: The user should remember that keywords cannot be used as variable names.

The keywords can also be called Reserved Words. The QBASIC keywords can be  classified into the following four categories. They are:

1. Assignment keywords: These keywords are used to assign a value to a related variable.. 

Example: LET, SWAP etc.

2. Input/output keywords: 

These keywords are used to input variables for processing and output the result on the screen, as their name implies.

Example: CLS, INPUT, LINE INPUT, PRINT, PRINT USING etc.

3. Declaration keywords: These keywords are used to define and declare the

variables, constants etc.

Example: DIM, REM,CONST, DECLAR, INT etc.

4. Control keywords: These keywords are used to change the flow of execution of statements.

Examples: IF THEN, SELECT CASE, FOR NEXT, DO LOOP, ON GOTO etc.

Some of the keywords are:

CLS:

Clear Screen, or CLS. We can use the CLS keyword to clear the output screen.

Syntax: CLS

Example:

CLS
PRINT “Hello world "
END

REM :

The REM is used to  add comments anywhere in the program.

It helps to make the source code simpler for humans to understand and is ignored while running the program,

Syntax: REM <comment>

Example:

REM This is a comment.
' Semicolon can also be used as comment.
PRINT "Hello"       
END

PRINT:

It  is used to display the output on the screen. 

We can also use question marks (?) instead of PRINT statement

or expressions are used with print statements. String expressions need to be enclosed in double quotes in order to be printed.

Syntax: PRINT <constants / variables / expressions>

Example:

PRINT ”Hello world”
PRINT 23

INPUT:

It is used to accept keyboard input when the program is running. This statement allows a user to input data into the computer’s memory. The corresponding variables store the input value.

Syntax: INPUT <“message”>; or, <variables>

Example:

CLS
INPUT "Enter your name"; name$
PRINT "Your name is:"; name$
END

END:

It  is used to terminate the execution of the program.  The END statement is typically used at the end of the program to stop further execution. 

Syntax: END

Example:

CLS
PRINT "I am learning Qbasic Programming language:";
END

LET:

It  is used to assign value to a variable. The LET statement allows us to assign any value to a variable.

Syntax: LET <variable> <constants / variables / expressions>

Example:

CLS
LET name$= "Dinga Vinga "
LET installs=45000
LET users= 10000
PRINT name$, installs, users
END

LINE INPUT:

It is used to input a line of data at a time and after entering it  acts as the string. It is commonly used to read a line from a sequential file into a String or Variant variable.

Syntax: LINE INPUT “prompt string”; string variable

Example:

CLS
LINE INPUT "Enter your name and email address"; n$
Print n$
END

LineInput used in file handling:

Open "Stduent.rec" For Input As #1
   Do While Not EOF(1)   
       Line Input #1, Name   
       Print Name   
   Loop
   Close #1  
END

SWAP:

SWAP keyword is used to  exchange the value of two variables having the same data types.

Syntax: SWAP variable1, variable2

Note: variables must be of the same type.

Example:

CLS
Input "Enter the first number";n1
Input "Enter the second number";n2
Print "Before using SWAP"; nl,n2
SWAP nl,n2
Print "After using SWAP"; nl,n2
End
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *