on gosub

ON offset GOSUB address0, address1, ...addressN

Offset - is a variable/constant which specifies which subprocedure to use (0-N).

Addresses - are labels which specify which subprocedure to gosub to.


Gosub address specified by offset (if in range).

This command allows a conditional gosub depending on the value of the variable 'offset'. If offset is value 0, the program flow will gosub to address0, if offset is value 1 program flow will gosub to adddress1 etc. If offset is larger than the number of addresses the whole command is ignored and the program continues at the next line. The return command of the sub procedure will return to the line after on...gosub. This command counts as a single gosub within the compiler.

Applies To:
See Also:
Related Create:

    Set LED according to variable value

    The 'on gosub' branch taken depends on the value of the b1 variable and as it increases a different LED will be set.

    Code Example:
    reset1:	let b1 = 0
    	low B.0
    	low B.1
    	low B.2
    	low B.3
    main:	pause 1000
    	inc b1
    	if b1 > 3 then reset1
    	on b1 gosub btn0,btn1, btn2, btn3
    	goto main
    btn0:	high B.0
    btn1:	high B.1
    btn2:	high B.2
    btn3:	high B.3
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.


    • Posted by johnlong

      Hi Technical

      The possitioning of the inc b1 is in the wrong place. Where it is the gosub btn0

      is not inacted

      To work correctly it needs to be


      pause 1000

      if b1 >3 then reset1

      on b1 gosub btn0,btn1,btn2,btn3

      inc b1

      As b1 would never be 0 at the gosub command

    • Login to leave a comment.