QBASIC Statements

QBASIC Statements:

Any command or the instructions in the QBASIC is called a statement. Statements are classified into executable and non-executable. Executable statement specify actions and non-executable statements specify characteristics, arrangements and initial values of data.

Some of the QBASIC statements are:

  1. CLS
  2. REM
  3. INPUT
  4. LET
  5. PRINT
  6. END
  7. PRINT USING
  8. LINE INPUT
  9. LPRINT AND LPRINT USING
  10. READ….DATA
  11. RESTORE
  12. LOCATE
  13. SWAP

1. CLS statement:

It clears the previous output from the display screen and makes the screen blank.

Syntax: CLS

2. REM statement:

REM or Remarks is non-executable statement where single quotation(‘) is used.

Syntax: REM <remark>

3. INPUT statement:

It receives input from the keyboard during the execution of the program.

Syntax: INPUT [“Message”] ; Variable

4. LET statement:

It is used to assign the value in the variable.

Syntax: LET [variable] = [expression]

5. PRINT statement:

It is used to display the output on the screen. Question mark (?) also can be used instead of PRINT command to display on the screen.

Syntax: PRINT[expression][{; | ,}]

6. END statement:

It is used at the end of the QBASIC program to terminate it.

Syntax: END

7. PRINT USING STATEMENT

Syntax: PRINT USING “formatting string”; expression

! Displays only the first character of string
\n\ Prints first n+2 characters from the string
& Displays all the string
# Digit position is spacified
&& Prints leading & sign
^^^^ Prints the number in exponential format
. Decimal point position specification

Example:

CLS

a$ = “Rudra”

b$ = “Bahadur”

c$ = “Rai”

PRINT USING “!”; a$; “.”;

PRINT USING “!”; b$; “.”;

PRINT USING “&”; c$;

END

8. LINE INPUT

This statement allows to input line of data at a time and assign in to single variable.

Syntax: LINE INPUT “string”; string variable

Example:

CLS

LINE INPUT “please enter the data”; n$

PRINT n$

END

9. LPRINT and LPRINT USING Statement

LPRINT statement is used to print the text to a printer

LPRINT USING statement is used to print formatted output to a printer.

Example:

CLS

a$ = “this is a test message”

LPRINT a$

END

Example:

CLS

A = 98765.4321

LPRINT USING “###,##,##”; A

END

10. READ….DATA Statement

It is used in conjunction with the DATA command which lets QBASIC to  read data. It is used mostly when dealing with large quantities of data in program.

Example:

CLS

READ a, b, c

PRINT a, b, c

DATA 10,20,30

END

Example:

CLS

READ E, C, N, S

T = E + C + N + S

P = T / 4

PRINT “the total is”; T

PRINT “the percentage is”;P

DATA 60,80,80,90

END

11. RESTORE Statement

Once the data element is read, it cannot be read again until the program resets it. The RESTORE statement is used to reset the data in the program.

Example:

CLS

READ a, b, c

PRINT a, b, c

RESTORE

READ d, e, f

PRINT d, e, f

DATA 10,20,30

END

12. LOCATE STATEMENT

It is used to move the cursor to the specified position on the screen.

Example:

CLS

LOCATE 11, 45

PRINT “Hellow World”

END

[11,45: ROW 11 and COLUMN 45 ]

13. SWAP Statement

The SWAP is an assignment statement. It exchanges the values of two variable.

Example:

CLS

INPUT “Enter the first number”; a

INPUT “enter the second number”; b

PRINT “Before using SWAP”; a, b

SWAP a, b

PRINT “After SWAP”; a, b

END