Rockwell-automation 1746-BAS BASIC LANGUAGE User Manual Page 107

  • Download
  • Add to my manuals
  • Print
  • Page
    / 280
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 106
Publication 1746-RM001A-US-P
Execution Control and Interrupt Support Functions 8-11
GOSUB
Purpose
Use the GOSUB statement to cause the module to transfer control of the program
to the line number [ln num] following the GOSUB statement. In addition, the
GOSUB statement saves the location of the statement following GOSUB on the
control stack so that you can perform a RETURN statement to return control to
the statement following the most recently executed GOSUB statement. You may
nest the GOSUB statement up to 9 times.
The control stack (C-stack) stores all information associated with loop control
(example: DO-WHILE, DO-UNTIL, FOR-NEXT and BASIC subroutines). The
control stack is 157 bytes long. DO-WHILE and DO-UNTIL loops and GOSUB
commands use 3 bytes of the control stack. FOR-NEXT loops use 17 bytes.
Syntax
GOSUB [ln num]
Examples
Simple Subroutine
READY
>1 REM EXAMPLE PROGRAM
>10 FORI=1TO5
>20 GOSUB 100
>30 NEXT I
>40 END
>100 PRINT I
>110 RETURN
READY
>RUN
1
2
3
4
5
READY
>NEW
Nested Subroutine
>1 REM EXAMPLE PROGRAM
>10 FORI=1TO3
IMPORTANT
Excessive nesting exceeds the limits of the control stack,
generating an error, and causing the module to enter Command
mode.
Page view 106
1 2 ... 102 103 104 105 106 107 108 109 110 111 112 ... 279 280

Comments to this Manuals

No comments