Home / GWBASIC Programming / Gw Basic in Urdu Part 4: 10 Class

Gw Basic in Urdu Part 4: 10 Class

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

GOTO,IF-THEN,FOR-NEXT ,STOP,END

gwbasic in urdu ,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

Example

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 .

Example

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.

IF statement

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”

Ok

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

Ok

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

50 end

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

10 n=1

20 while n<=10

30 print n

40 n=n+1

50 wend

60 end

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

Example

10 on error goto 40

20 print “happy”

30 printy “bbb”

40 print “error here “

Ok

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

70 end

Result

Pakistan

Pakistan

Lahore

Pakistan

Pakistan

Lahore

Pakistan

Pakistan

Lahore

Example: 1

10 For A=5 to 1 step-1

20 FOR B=1 to A

30 Print “x”

40 Next B

50 Print

60 Next A

70 end

Result

Xxxxx

Xxxx

Xxx

Xx

X

if you are new on my Gw Basic then check also part 3

Also Watch Video

 

The following two tabs change content below.
Hi I am Ch Shahbaz from Pakistan.I love to writing different type of informative Articles. By profession i am a Pro Blogger, Web Developer, Graphic Designer and Creative writer.

Latest posts by Ch Shahbaz (see all)

Check Also

Gwabasic in urdu

Gw Basic in Urdu Part 3: 10 Class

Now we will discuss about some of operators of GW basic ,which is one of the …

One comment

  1. good job

Leave a Reply

Your email address will not be published. Required fields are marked *