Whenever you GOSUB somewhere the adress after from where you GOUSBed is pushed onto the stack (stored in memory). If another GOSUB is executed the adress after THAT gosub is pushed onto the stack and the first adress stored is "pushed down". When a RETURN is executed the adress at the top of the stack is popped (retreived) and the execution jumps to that adress. This is how it works in any language, not just PBP.

If you GOSUB somewhere you must go back with a RETURN.
You can not RETURN from somwhere to where you did not GOSUB.

This too is NOT unique to PBP.

Now, it's perfectly fine to use GOTO from a subroutine to which you jumped with a GOSUB as long as you eventually end up at a "matching" RETURN. Example:
Code:
Main:
Toggle PortB.0
Pause 100
GOSUB CheckSwitch
Goto Main

CheckSwitch:
If PortA.0 = 1 THEN
GOTO DoThis
ELSE
GOTO DoThat
ENDIF
RETURN

DoThis:
' Whatever
RETURN

DoThat:
' Whatever
RETURN
In the above example the RETURN instryction at the end of DoThis and DoThat "matches" the GOSUB in the Main loop, Everything is fine. However, if you in somewhere in the main loop (or whatever) did a GOTO DoThat things would go bad because there's a "non matching" RETURN at the end. When the execution hits that RETURN it will pop "something" of off the stack and go there - not what you want.

Again, this is NOT unique to PBP in any way.

/Henrik.