Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARRAY declaration in GOSUB routines.
#2
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.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
ARRAY declaration in GOSUB routines. - by bartok - 02-04-2024, 01:05 PM
RE: ARRAY declaration in GOSUB routines. - by bplus - 02-04-2024, 03:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  getting the number of dimensions in an array on the fly? madscijr 7 732 09-16-2025, 12:34 AM
Last Post: madscijr
  Quesiton on Dimensioning an Array Dimster 5 990 02-06-2024, 01:55 PM
Last Post: Dimster
  Array in an array NasaCow 78 15,511 04-12-2023, 10:53 AM
Last Post: TempodiBasic
  Can images be read from a file into an array? PhilOfPerth 11 2,504 02-17-2023, 03:31 AM
Last Post: TerryRitchie
  Swapping array elements PhilOfPerth 24 3,902 11-19-2022, 12:16 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)