📖⚡GOSUB

Jump to a subroutine in the processor, then continue execution from the current position after executing a RETURN statement.

 

Syntax

GOSUB LabelName

Example

GOSUB MyLabel


 

' GOSUB Example
' Gosub.txt
' Kic8 

 ' Our main loop repeats forever,
 ' within the loop we execute our subroutine.

DO 
  GOSUB FireLasers
LOOP 

FireLasers:
  TOGGLE 0
  TOGGLE 0
  RETURN ' Leave this subroutine

Nested Example

' Nested Gosub Example
' GosubNested.txt
' Kic8 
' Studio Tip: Open the Call Stack Window And Study It..

DO 
  GOSUB FireAndPause
LOOP 

FireAndPause:
  GOSUB FireLasers  ' Fire Laser (NOTE: Going into nested subroutine)
  PAUSE 1000        ' Recharge for 1000 ms
  RETURN            ' Leave this subroutine

FireLasers:
  TOGGLE 0
  TOGGLE 0
  RETURN            ' Leave this subroutine

todo: 

Tutorials: Subroutines

Related Commands: