Sei sulla pagina 1di 3

Written by: - SHAHZAD IFTIKHAR Contact # 0313-7891989, 0333-5319544

e-mail: shahzad2sunny@hotmail.com website: www.eservicespakistan.com

COMPUTER SCIENCE FOR 10TH CLASS (UNIT # 11)


============================================================
Read Instructions before study:
• Bullet means you have to write the answer in paragraph shape and you could not change
the sequence. Bullets are used only for your ease.
i) Roman numbered, question may be written as it is. However sequence can be changed.
*** This item should not be written in answer. It is just a hint for you.
Pay more attention on the bold text in answers.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

THEORY
Question: What is transfer of control? Give an example which causes transfer
of control?
• In all programs, computer executes instructions in numerical order, from smallest
to largest one.
• However the order the execution can be changed using control statements.
• One control statement is GOTO statement, that causes the control to transfer
anywhere within the program.
Example:
10 REM * ENDLESS GOTO LOOP OF WELCOME MESSAGE*
20 INPUT “PLEASE ENTER YOUR NAME:” ; A$
30 PRINT “WELCOME” ; A$
40 GOTO 30
50 END

Question: What is the difference between conditional and unconditional


transfer of control? Give example of each type.
Unconditional transfer of control:
If we use GOTO statement without defining any condition for transfer, then it is called
unconditional transfer of control.
Example:
10 REM * ENDLESS GOTO LOOP OF WELCOME MESSAGE*
20 INPUT “PLEASE ENTER YOUR NAME:” ; A$
30 PRINT “WELCOME” ; A$
40 GOTO 30
50 END
Conditional transfer of control:
If we use GOTO statement along with proper condition for transfer, then it is called
conditional transfer of control.
Example:
10 REM * GOTO LOOP OF WELCOME MESSAGE *
15 REM * PROGRAM STOPS WHEN A$ IS NAVEED *
20 INPUT “PLEASE ENTER YOU NAME” ; A$
30 PRINT
40 PRINT “WELCOME” ; A$
50 IF A$ = NAVEED THEN GOTO 70
60 GOTO 20
70 PRINT “THERE IS A MESSAGE FOR YOU”
80 END

============================================================
Visit www.eservicespakistan.com for Notes, Syllabus, Old Papers, Home Tuitions, Jobs & much more
(Page 1 of 3)
Written by: - SHAHZAD IFTIKHAR Contact # 0313-7891989, 0333-5319544
e-mail: shahzad2sunny@hotmail.com website: www.eservicespakistan.com

COMPUTER SCIENCE FOR 10TH CLASS (UNIT # 11)


============================================================
Question: How do FOR … NEXT statement differs from IF … THEN statement?
IF … THEN Statements:
If a statement transfers control to some other part of the program provided the
condition is true. IF… THEN … ELSE statement transfers control to another part of the
program when the condition is false. The format of IF… THEN … ELSE statement is: -

Line # If (condition) THEN (Statement 1) ELSE (Statement 2)

For … NEXT Statement:


The purpose of FOR statement at the beginning of the loop is to name the counter
and put its initial and final values. The NEXT statement indicates the end of the loop,
increments the counter and then tests the counter.

Question: What is multiple branching? Write a program to explain multiple


branching using ON GOTO statement.

Question: What is the difference between controlled loops and counter


loops?

Question: What is the purpose of FOR statement in the FOR … NEXT loop.
Explain with example.
The purpose of FOR statement at the beginning of the loop is to name the counter
and put its initial and final values. The NEXT statement indicates the end of the loop,
increments the counter and then tests the counter.

Question: How do WHILE … WEND loop differ from FOR … NEXT loop?
FOR … NEXT loop: -
In some cases a part of a program is repeated several times. It is necessary to use a
loop to execute the part of the program repeatedly. A combination of IF … THEN and
GOTO statements can be used to perform looping.
WHILE … WEND loop: -
WHILE … WEND statements is used to execute a series of statements in a loop as
long as a given condition is true. If the condition is false, the loop ends and the
program continues to the line following EEND.

Question: Explain the use of ON … ERROR GOTO statement?


The ON ERROR GOTO statement suppressed error message. As soon as an error
occurs, it transfers control to the line number specified. The ON ERROR OFF no longer
suppresses error message and the computer handles error in the normal way. The
Report command prints out the error message for the last error.

============================================================
Visit www.eservicespakistan.com for Notes, Syllabus, Old Papers, Home Tuitions, Jobs & much more
(Page 2 of 3)
Written by: - SHAHZAD IFTIKHAR Contact # 0313-7891989, 0333-5319544
e-mail: shahzad2sunny@hotmail.com website: www.eservicespakistan.com

COMPUTER SCIENCE FOR 10TH CLASS (UNIT # 11)


============================================================
Question: What is meant by nested loop(s)? Illustrate the use of Nested loop
using FOR … NEXT statement.
FOR … NEXT loops may be nested; i.e. a FOR … NEXT loop may be placed inside
another FOR … NEXT loop. The following conditions must be met while nesting a FOR
… NEXT loop.
• Each loop must have a different variable name as its counter.
• The NEXT of inner loop must appear before the outer loop.
• If nested loops have the same end point, a single NEXT statement may be used
for all of them.
Example:
10 REM ** K LOOP IS NESTED WITHIN J LOOP **
20 FOR J = 1 TO 2
30 PRINT : PRINT “PAKISTAN”
40 FOR K = 1 TO 3
50 PRINT “ZINDA BAD”
60 NEXT K
70 NEXT J
80 END
=*=*=*=*=

More works/Tasks:
Do Objectives from book & from any other objective book.
Do Interesting Information from book.
Do Scientific Reasons with the help of teacher.

============================================================
Visit www.eservicespakistan.com for Notes, Syllabus, Old Papers, Home Tuitions, Jobs & much more
(Page 3 of 3)

Potrebbero piacerti anche