IF...THEN and RETURN
SteveD
Posts: 64
I understand that when a GOSUB instruction sends the program to a subroutine that contains a RETURN command the program will return to the next instruction following the initial GOSUB instruction.
My question is if a GOSUB instruction sends the program to a subroutine that contains an IF…THEN statement that sends the program to another subroutine which contains a RETURN, will the program go back to the next instruction following the IF…THEN or will it be directed to the instruction following the initial GOSUB instruction?
·
Thanks
My question is if a GOSUB instruction sends the program to a subroutine that contains an IF…THEN statement that sends the program to another subroutine which contains a RETURN, will the program go back to the next instruction following the IF…THEN or will it be directed to the instruction following the initial GOSUB instruction?
·
Thanks
Comments
When you say "send the program to another subroutine" do you mean with GOTO or with GOSUB.
If you use GOSUB then it will return back to the IF...THEN if you use GOTO it will return back to the calling program.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Forget about the past, plan for the future, and live for today.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
engineer, fireman, bowler, father, WoW addict [noparse];)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99, FREE shipping until 2006!
Product web site: http://www.allsurplus.net/Axiom/
temp
temp1
temp2
GOTO main
TEMP:
code
return
TEMP1:
IF "statement true" THEN temp
RETURN
TEMP2:
code
RETURN
I believe I am referring to GOSUB.
"THEN temp" is the same as "GOTO temp" so that will NOT return back to the line after the "IF".
If you want it to then do this:
IF "statement true" THEN
temp
ENDIF
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Forget about the past, plan for the future, and live for today.
·
I do not want it to return back to the line following the IF.
So when the IF instruction sends to temp where will it go after it comes to the RETURN that is in the temp subroutine? I was thinking it would continue on to temp2. Would the following be the correct flow of the example program?
(GOSUB) temp
temp (subroutine)
code
return
(GOSUB) temp1
IF…THEN (GOTO) temp
temp (subroutine)
code
return
(GOSUB) temp2
code
return
goto main
RETURN will send the program back to the line after the [noparse][[/noparse]implied] GOSUB that was last used. You can have conditionals that use GOTO in the mix.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Here is some stuff I do to save code space.
Let's say I need a routine to turn on an LED and then delay for 10mSec.
I also need another routine to turn off the LED and then delay for 10mSec.
Then I also need anouther routine to just delay for 10mSec.
Okay so here is some very space effecient code:
Sorry about lines, I don't know how I made them appear ???
Notice how LEDoff will just "fall-into" the Delay10 routine.
I hope this helps explain it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Forget about the past, plan for the future, and live for today.
Post Edited (Bean (Hitt Consulting)) : 12/16/2005 11:59:29 AM GMT
It appears that I was trying to make it more difficult than it is, but I needed positive reinforcement to be sure.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Forget about the past, plan for the future, and live for today.
·