Goto/Gosub + If

Started by biolizard89, April 17, 2013, 08:06:45 AM

Previous topic - Next topic

biolizard89

If I have a GoTo or GoSub inside an if, what happens to the execution status in the code handler after the GoTo/GoSub takes place?  Is the following pseudocode for Gecko codes acceptable?

If condition
GoSub x
EndIf
More commands...
x:
More commands...

Since we never executed the EndIf directly, does the code handler still think it's inside an If when it reaches x:?

dcx2

Gosub code type 68 is meant to be used with Return code type 64, so the end-if would be executed in this case.

For Goto code type 66, you will still be "inside" the if.

Being inside an active if probably isn't a big deal, although I'm sure there are some corner cases where things can go wrong.  The bigger problem is that you must protect your Gosub destination with something so that the code handler doesn't execute it when your if condition is false (or after it Returns)