Return – Rockwell Automation 1771-DB BASIC MODULE User Manual
Page 186
Advertising
![background image](/manuals/579953/186/background.png)
Chapter
Statements
11
11 -34
Use the RETURN statement to return control to the statement following
the most recently executed GOSUB (page 11 -13). Use one return for each
GOSUB to avoid overflowing the control stack. This means that a
subroutine you call with the GOSUB statement can call another subroutine
with another GOSUB statement.
Syntax
RETURN
Example
Simple Subroutine
>1 REM EXAMPLE PROGRAM
>10 FOR I = 1 TO 5
>20 GOSUB 100
>30 NEXT I
>40 END
>100 PRINT I
>110 RETURN
READY
>RUN
1
2
3
4
5
Nested Subroutine
>1 REM EXAMPLE PROGRAM
>10 FOR I = 1 TO 5
>20 GOSUB 100
>30 NEXT I
>40 END
>100 PRINT I,
>110 GOSUB 200
>120 RETURN
>200 PRINT I*I,
>210 GOSUB 300
>220 RETURN
>300 PRINT I*I*I
>310 RETURN
READY
>RUN
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
RETURN
Advertising