A Gosub is part of the main or subroutine as they share variables with the main or subroutine depending where they reside but they are put off into their own little private corner to run a repetitious bit of code over and over without interferring with the main or subroutine.
That is one main difference between a Gosub and "real" sub or function, the GoSub uses or shares variables with the main or subroutine it resides in. A "real" sub or function uses it's own set of variables different from the Main code set of variables. The other difference is that a "real" sub or function can have variables shared with main through the call eg, mySub var1, var2, ... whereas you only call a Gosub: myGosub the name alone.
A variables or array declaration section in a GOSUB can be moved to the top of Main or Subroutine and should be so you don't redeclare the variables and arrays each time the gosub is used by the main or subroutine, that's redundant and inefficient.
And another difference between a GoSub and a "Real" sub or function: The "real" subs or functions can be called by either another sub or function, the main program or even by a gosub part of main or subroutine. "Real" subs or functions are like completely independent little programs, you can even copy then and use them in other programs! That's the beauty of a really good Sub or Function and thus you can build Libraries of Subs and Functions, say for advanced array handling or file stuff or even GUI's or little interpreters.
That is one main difference between a Gosub and "real" sub or function, the GoSub uses or shares variables with the main or subroutine it resides in. A "real" sub or function uses it's own set of variables different from the Main code set of variables. The other difference is that a "real" sub or function can have variables shared with main through the call eg, mySub var1, var2, ... whereas you only call a Gosub: myGosub the name alone.
A variables or array declaration section in a GOSUB can be moved to the top of Main or Subroutine and should be so you don't redeclare the variables and arrays each time the gosub is used by the main or subroutine, that's redundant and inefficient.
And another difference between a GoSub and a "Real" sub or function: The "real" subs or functions can be called by either another sub or function, the main program or even by a gosub part of main or subroutine. "Real" subs or functions are like completely independent little programs, you can even copy then and use them in other programs! That's the beauty of a really good Sub or Function and thus you can build Libraries of Subs and Functions, say for advanced array handling or file stuff or even GUI's or little interpreters.
b = b + ...