17.07.2013 Views

GWBASIC User's Manual

GWBASIC User's Manual

GWBASIC User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GW-BASIC <strong>User's</strong> Guide<br />

GOSUB ... RETURN Statement<br />

Purpose:<br />

To branch to, and return from, a subroutine.<br />

Syntax:<br />

GOSUB line number<br />

.<br />

.<br />

.<br />

RETURN [line number]<br />

Comments:<br />

line number is the first line number of the subroutine.<br />

A subroutine may be called any number of times in a program, and a subroutine may be called<br />

from within another subroutine. Such nesting of subroutines is limited only by available memory.<br />

A RETURN statement in a subroutine causes GW-BASIC to return to the statement following the<br />

most recent GOSUB statement. A subroutine can contain more than one RETURN statement, should<br />

logic dictate a RETURN at different points in the subroutine.<br />

Subroutines can appear anywhere in the program, but must be readily distinguishable from the<br />

main program.<br />

To prevent inadvertent entry, precede the subroutine by a STOP, END, or GOTO statement to direct<br />

program control around the subroutine.<br />

Examples:<br />

10 GOSUB 40<br />

20 PRINT "BACK FROM SUBROUTINE"<br />

30 END<br />

40 PRINT "SUBROUTINE";<br />

50 PRINT " IN";<br />

60 PRINT " PROGRESS"<br />

70 RETURN<br />

RUN<br />

SUBROUTINE IN PROGRESS<br />

BACK FROM SUBROUTINE<br />

The END statement in line 30 prevents re-execution of the subroutine.<br />

file:///C|/Documents%20and%20Settings/Lorenzo/Desktop/GW%20Basic/GOSUB.html28/03/2004 21.29.28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!