Statement: goto [ln num – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 61

Advertising
background image

Operating Functions

Chapter 5

5–24

RETURN

Use this statement

to “return” control to the statement following the

most recently executed GO SUB STATEMENT. Use one return for each
GOSUB to

avoid overflowing the C-STACK. This means that a

subroutine

called by the GO SUB statement can call another

subroutine with another GOSUB statement.

Examples:

SIMPLE SUBROUTINE NESTED SUBROUTINES

u10 FOR I=1 TO 5

u10 FOR I=1 TO 3

u20 GOSUB 100

u20 GOSUB 100

u30 NEXT I

u30 NEXT I

u40 END

u40 END

u100 PRINT I

u100 REM USER SUBROUTINE HERE

u110 RETURN

u105 PRINT I,

uRUN

u110 GOSUB 200

1

u200 PRINT I,I*I

2

u210 RETURN

3

uRUN

4

5

1 1
2 4

READY

3 9

u

READY

u

Mode: COMMAND AND/OR

RUN

Type: CONTROL

The GOTO [ln num] statement

causes BASIC to transfer control directly

to the line number ([ln

num]) following the GOTO statement.

Example:

u50 GOTO 100

If

line 100 exists, this statement causes execution of the program to

resume at line 100. If line number 100 does not exist the message ERROR:
INVALID

LINE NUMBER is printed to the console device.

5.4.12
Statements: GOSUB [ln num]
– RETURN (continued)

5.4.13
Statement: GOTO [ln num]

Advertising