What is meant of Transfer of control in GW Basic
In GWBASIC the program is executed in sequence or line by line. But if we want to jump form one part to another part of program then we use control statement .This execution of program is called transfer of control.
These are the control statement are used in GW Basic
But here are two types of such statements
1.Conditional transfer in Gw Basic
If we want to jump in program on some specific condition then we use conditional transfer
10 let m=50
20 If m>33 then print “pass” else “fail”
2.Unconditional transfer in GW Basic
If we want to move control without any condition then we use unconditional transfer .
10 print “x”
20 print ”Y”
30 goto 10
Conditional transfer of control statements
If the control of any statement transfer form one part to another on some condition is known as conditional transfer of control… IF/THEN/ELS.
10 input s
20 if s<20 then print “happy “
In this statement if the input is greater then 20 then program will print happy otherwise it will be terminated.
IF then else statement
10 input z
20 if z> then 30 else 40
30 print “pass”: END
40 print “fail”
THE ON/GO TO statement GW Basic
-It is multiple branching unconditional transfer of control statement which is used to transfer control to any one of the indicated line numbers.
e.g., 40 on choice GO TO 15,35,60,100,60.
10 input n
20 on n goto 30, 40, 50
30 print “a”: end
40 print ”b”:END
50 print”c”: end
Here if you give input 1 the program will print lin2 number 30 if 2 then 40 if 3 then 50
FOR/NEXT LOOP statement: – It is used where we now it advance that how much time the program will be executed.
10 for k=1 To 10 step 1
30 print k
40 Next k
While wend loop in GW Basic
It is used where we do not know in advance that how much time the program will be executed
20 while n<=10
30 print n
On error got to GW Basic
In or error goto statement the control will be transfer to specific line when there is error accrued in program
10 on error goto 40
20 print “happy”
30 printy “bbb”
40 print “error here “
In this program the error is occurred at line number 30 and the control is transfer to line number 40 as specified above in line 10
What is loop and what is nested loop
Loops are used to execute one statement more than one time, when we use loop within a loop is called nested loop.
Write a program which print 1 time Lahore and 2 time Pakistan and this procedure will be continue till 3 time by using nested loo
10 for a=1 to 3 step 1
20 for b=1 to 2 step1
30 print “Pakistan”
40 next b
50 print “Lahore”
60 next a
10 For A=5 to 1 step-1
20 FOR B=1 to A
30 Print “x”
40 Next B
60 Next A
if you are new on my Gw Basic then check also part 3
Also Watch Video