PDA

View Full Version : gosub - return



l_gaminde
- 7th August 2010, 20:24
I need to use the following code two different ways I need to gosub to this section and also in another section either goto or just let it continue through to this section from the code just above it. With this second idea of the code rolling through will the return be skipped or will it get in the way somehow??

Power_On:
Value = 100
counter =0
gosub Send_command
pause 500
Return

Kamikaze47
- 8th August 2010, 08:07
Why not just move it somewhere out of the way and place a GOSUB Power_On where it used to be?

l_gaminde
- 8th August 2010, 18:22
Yes this is what I did,
but I would still like to know what it does and if it would mess up somehow

Kamikaze47
- 8th August 2010, 18:26
I haven't tried it personally because its never really necessary.

If you want to know what happens, try it :)

BrianT
- 11th August 2010, 10:21
DoSomeTimes:
code block 1
DoOften:
code block 2
Return

The above structure lets you have two separate entry points with a single return. I use this structure when I want to recalibrate a sensor for example.

Calling GOSUB DoOften gets the result of the sensor.
Calling GOSUB DoSomeTimes starts with a calibration routine then gets the results of the sensor.

your mileage may vary but the idea works for me.

HTH
BrianT