GoSub Statement

 gosub-statement = (("Go" "Sub") / "GoSub") statement-label  

Static Semantics.

§ A procedure containing a <gosub-statement> MUST contain exactly one <statement-label-definition> with the same <statement-label> as the <statement-label> defined in the <gosub-statement>.


Runtime Semantics.

§ A <gosub-statement> causes execution to branch to the <statement> immediately following the <statement-label-definition> for <statement-label>. Execution continues until the procedure exits or a <return-statement> is encountered.

§ If the <statement-label> is the same as the <end-label> of lexically enclosing procedure declaration execution of the current <procedure-body> immediately completes as if statement execution had reached the end of the <procedure-body> element’s contained <statement-block>.

§ Each invocation of a procedure creates its own GoSub Resumption List that tracks execution of each <gosub-statement> and each <return-statement> within that procedure in a last-in-first-out (LIFO) manner. Execution of a GoSub statement adds an entry for the current <gosub-statement> to the current procedure’s GoSub Resumption List.