The flow of the program will first call
My_line_label via gosub, where it render the text statement then hits RETURN. Upon return, execution continues on from the next line after the
Gosub My_line_label. So it'll happily execute code at and beyond My_Line_Label section of code until it hits the RETURN statement, where it should error at this point.
Labels are treated as markers, they don't actually prohibit the program flow of execution from the entering a labeled section without being called. If that's what you want to it's time to look at
Functions.
To stop the second execution of the sub routine in you example you'd need to END, or jump past to some other Location.
myvar AS DWORD = 1
GoSub _my_line_label
; Tell it end before it runs into the sub routine code
END
my_line_label:
IF myvar = 0
GOTO _skip_to_end
ENDIF
TEXT 0, 0, "Hello World!"
_skip_to_end:
Return
In real world app using sub routines, you'd structure the project so you're not jumping around all over the place though. Personally if you're going to use GOTO/GOSUB then set yourself a rule and stick to it. Like Goto/Gosub may only branch forward and not inside nests.
ie.
Gosub Initialize
Gosub PlayGame
end
Initialize:
DIm BadGuys(100)
etc
etc
return
PlayGame:
do
Gosub HandleBadGuys
Gosub HandlePLayer
gosub DrawScene
until Player=Dead
return
HandleBadGuys:
For lp=0 to NumberOFBadGuys
control the bag guys
next
return
HandlePLayer:
move player
return
DrawScene:
cls
draw bad guys
draw player
sync
return
It's also helpful to set up sub-routines so that have a single entry point and single exit point.