QBASIC Statement For Class 8
QBASIC Statement For Class 8
Statement are the set of instruction using keyword or command in QBASIC to write program. It tells the QBASIC
editor "what to do". Eg: LET, INPUT,CLS, END etc.
TYPES OF STATEMENT
General Statement
General statement are the basic statement must written to run a program. these statement are
needed to write a program. some of these statement are executable and some are not executable.
Eg: CLS, LET, INPUT, PRINT, END, REM, READ...DATA, SWAP etc.
Program to find product of three given number using READ... DATA statement.
CLS
READ A,B,C
PRODUCT = A * B * C
PRINT PRODUCT
DATA 25,30,50
END
In above program, Read statement is used to read the data from data statement and
assign them to related variables.
TRY YOURSELF
Write QBASIC program
To enter your name,address,contact no. and display it.
To find area of rectangle
To find area of square
To find area of circle
To find perimeter of rectangle
To find simple interest
To find circumference of circle
To find perimeter of four walls [2h(l+b)]
To convert Meter into centimeter and vice versa
To convert IC into NC and vice versa
To convert DOLLAR into NC and vice versa
Control Statement
Control statement are the statement that control the flow of the program. It can be used to check
condition and alter the flow in appropriate position. In simple word, program flow in sequential
order i.e from top to bottom but with the help of control statement user can change or alter the
flow of program according to the condition or requirement.
it can be divided into following types:
a. Jumping Statement: It jump from one statement to another statement. It is unconditional
statement. Goto statement is the type of jumping statement.
CLS
C:
LET A$ = "KALIKA"
PRINT A$
GOTO C:
END
In above program, GOTO statement is used. this program display "KALIKA" infinitely
because this program is unconditional. this loop is called infinite loop.
IF statement check the condition and give result when condition is satistied. there are three
types of IF statement.
1. IF....THEN
2. IF....THEN....ELSE
3. IF....THEN....ELSEIF...ELSE
1. IF....THEN Statement: This statement is also called one branching statement. It check the
statement and give result only if the condition satisfied.
Eg:
CLS
INPUT "ENTER YOUR MARK"; M
IF M>=40 THEN
PRINT "PASSED"
END IF
END
In above program, IF....THEN statement is used. In this program condition is check
(M>=40), if condition satisfied then it give result "PASSED" otherwise it give nothing.
2. IF....THEN....ELSE Statement: This statement is also called two branching statement. It
check the condition and give both result true and false. If condition become true then it
display message after THEN and if condition become false then it display message after
ELSE.
Eg:
CLS
INPUT "ENTER YOUR MARK"; M
IF M>=40 THEN
PRINT "PASSED"
ELSE
PRINT "FAILED"
END IF
END
In above program, IF....THEN....ELSE statement is used. In this program condition is
check (M>=40), if condition satisfied then it give result "PASSED" otherwise it give result
"FAILED".
3. IF....THEN....ELSEIF....ELSE Statement: This statement is also called multi-branching
statement. It check many condition and give result when condition is satisfied.
Eg:
CLS
INPUT "ENTER YOUR PERCENTAGE"; P
IF P>=80 THEN
PRINT "DISTINCTION"
ELSEIF P>=60 AND P<80 THEN
PRINT "FIRST DIV"
ELSEIF P>=40 AND P<60 THEN
PRINT "SECOND DIV"
ELSE
PRINT "******"
END IF
END
In above program, IF....THEN....ELSEIF...ELSE statement is used. In this program many
condition is there , it check the first condition if it is satisfied then it give result otherwise it
goes to next condition and it goes so on.
SELECT CASE STATEMENT: SELECT CASE statement is also a multi-branching statement like
IF...THEN...ELSEIF...IF statement. it also check the first condition(case) if it is satisfied then
it give result otherwise it goes to next condition(case) and it goes so on.
Eg:
CLS
INPUT "ENTER YOUR PERCENTAGE"; P
SELECT CASE P
CASE 80 TO 100
PRINT "DISTINCTION"
CASE 60 TO 79
PRINT "FIRST DIV"
CASE 40 TO 59
PRINT "SECOND DIV"
CASE ELSE
PRINT "******"
END SELECT
END
In above program, SELECT CASE statement is used. In this program many condition is
there, it check the first condition(case) if it is satisfied then it give result otherwise it goes
to next condition(case) and it goes so on.
TRY YOURSELF
Write a QBASIC program
To check a person can vote or not
To check number is odd or even
To check greatest among two number
To check greatest among three number
To check smallest among two number
To check smallest among three number
To check it is divisible by 4 or not
To check it is divisible by 5 or not
To display the result according to the following information
Percent Grade
More than 90 A+
Between 80 and 90 A
Between 70 and 80 B+
Between 60 and 70 B
Between 50 and 60 C+
Between 40 and 50 C
Below 40 E
To enter a destination, No of passengers and calculate total fare with the help of
following rate lists.
Destination Fare Rate
KATHMANDU Rs. 750/person
POKHARA Rs. 600/person
NEPALGUNJ Rs. 900/person
BIRGUNJ Rs. 1200/person
SURKHET Rs. 900/person