Thursday, November 22, 2018

QBASIC STATEMENTS CLASS-VI

CONTROL STATEMENT- 
 The Control Statements are used for controlling the Execution of the program. We use control statements by two way
1) Unconditionally &
2) Conditionally


GOTO STATEMENT-

Unconditionally, we use GOTO statement. The Goto Statement is used for transferring the control to the other location for example- if you wants to transfer the control to the other place of the program then we can use the goto statement. When we use goto Statement then we have to supply a name along with a Goto Statement on which Control is transferred. The Name is user choice and Name must be defined with the help of a Colon. When Compiler transfers the Control of program to the Goto statement then statements of Goto block will be Executed and The Name of Goto Statements block is also called as the Label Name.

GOTO statement uses line number or label

Here, We will understand by an example

CLS
1 PRINT " MY NAME IS  AMIT " :GOTO ABC
2 PRINT " I LIVES IN RAEBARELI " : GOTO 4
3 PRINT " MY MOTHER NAME IS SHAILJA " :GOTO 2
ABC:
PRINT "MY FATHER NAME IS RAJESH " :GOTO 3
4 END

In the above program, line 1 will be executed and then goto will call the label ABC which has code MY FATHER NAME IS RAJESH & will call to line number 3 i.e. MY MOTHER NAME IS SHAILJA & then line 2 will be called I LIVES IN RAEBARELI & then line 4 will be executed with END.
In this way, GOTO statement will execute.


Example:-



Output:- 


IF THEN STATEMENT-

IF THEN checks the condition and execute the code if condition becomes true otherwise it move to the next call code. It uses Relational operators to check the conditions.

RELATIONAL OPERATORS
> greater than
>= greater than equal to
< less than
<= less than equal to
= equal to
<> not equal to
Note :- Relational operators always return Boolean values i.e. either ZERO or NON-ZERO. ZERO means false & NON-ZERO means true

Let's how IF statements works

Example:- 

CLS
A=10
IF A>5 THEN
PRINT A ; " IS GREATER"
END IF
END

Output:-

10 IS GREATER

In the above program, we have declared the value to A=10, and then applied condition using IF , IF will check the condition i.e. A > 5, if A will  be greater than 5 then it will print 10 IS GREATER, Otherwise, IF will end and then program will end


IF THEN ELSE-

IF THEN ELSE statement is used to check the condition. 

Example:-




 Output:-


 Here AGE is a variable which store age which you enters and if statement will checks the condition i.e. age is greater than equal to 18 or not ,if you will enter age greater than equal to 18 then it will display YOU ARE ELIGIBLE FOR VOTING and if you will enter less than 18 then it will display  YOU ARE NOT ELIGIBLE FOR VOTING. 


Let's see one more example-
Example:- 
Make a program in which ask the user to type amount which he/she has. If amount is greater than 100 then it will display you can order pizza otherwise it will display you can not buy pizza.


Output:-


IF THEN ELSEIF-

IF THEN ELSEIF is used to when we have to check multiple conditions and user has to select to one then we use IF THEN ELSEIF.

Lets see a brief description of IF THEN ELSEIF with an example.

Here, We will make a program to check greatest values among three values.

Example:-


Output:-




LAB ACTIVITY 
1) Write a program. (PAGE NO. 119)

a) To Accept the name from the user and print it.


CLS
INPUT " ENTER NAME "; N$
PRINT  " MY NAME IS ";N$
END


b) To Accept first name and last name in two separate variables and print that continuously


CLS
INPUT " ENTER YOUR FIRST NAME "; F$
INPUT " ENTER YOUR LAST NAME " ; L$
PRINT " MY NAME IS  "; F$ ; L$
END


c) To Accept two numbers and print their sum.


CLS
INPUT  " ENTER FIRST NUMBER "; NUM
INPUT " ENTER SECOND NUMBER "; NUM2
NUM3= NUM + NUM2
PRINT " THE SUM OF TWO NUMBER IS "; NUM3
END


d) To ask the user to enter three numbers , and calculate the product of them. Print with appropriate message.


 CLS
INPUT " ENTER FIRST NUMBER "; A
INPUT " ENTER SECOND NUMBER "; B
INPUT " ENTER THIRD NUMBER ";C
P= A * B * C
PRINT " THE PRODUCT OF THREE NUMBERS IS "; P
END



e) To ask the user to enter principal, rate and time , and calculate simple interest.



CLS
INPUT " ENTER PRINCIPAL "; P
INPUT " ENTER RATE OF INTEREST P.A "; R
INPUT " ENTER TIME IN YEARS" ; T
SI=P * R* T / 100
PRINT " THE SIMPLE INTEREST OF GIVEN VALUES IS "; SI
END

3) Write a program. (PAGE NO. 120)

a) To Accept the name from user , and print "HELLO" with name , if the name is RAMAN


CLS
INPUT " ENTER NAME " ; N$
IF N$= " RAMAN" THEN
PRINT " HELLO " ; N$
END IF
END


b) To Accept name and nationality of the person and print welcome, if he is INDIAN.


CLS
INPUT " ENTER YOUR NAME " N$
INPUT " ENTER YOUR NATIONALITY " ; A$
IF A$="INDIAN"  THEN
PRINT " WELCOME....." ; N$
END IF
END


c) To Accept two numbers and print the greater one.


CLS
INPUT " ENTER TWO NUMBERS "; A, B
IF A > B THEN 
PRINT A ; "IS GREATER"
ELSEIF B > A THEN 
PRINT B" "IS GREATER"
ELSE 
PRINT " BOTH ARE EQUAL"
END IF 
END


d) To Ask the user to enter any number, and print it is even or odd.


CLS
INPUT " ENTER NUMBER "; A
R= A / 2
IF R =0 THEN
PRINT " IT IS EVEN NUMBER "
ELSE
PRINT "IT IS ODD NUMBER "
END IF 
END


e) To Ask the user to enter two numbers, and divide the greater one with smaller.


CLS
INPUT " ENTER FIRST NUMBER "; A
INPUT " ENTER SECOND NUMBER " ; B
IF A > B THEN
D= A / B
PRINT " THE QUOTIENT IS "; D
ELSEIF B> A THEN
Q= B / A
PRINT " THE QUOTIENT IS "; Q
ELSE
PRINT " THE QUOTIENT IS " ; 1
END IF 
END






 

 
 
























 

1 comment:

Thank you so much to like us.