FutureBasic Logo

<<    Index    >> FutureBasic 5

begin globals   statement

begin globals
  [statements including variable declarations]
end globals

The begin globals and end globals statements indicate the beginning and end, respectively, of a section of global variable declarations. A global variable is one which is "visible" to all parts of the program that follow its declaration (except local mode functions). It maintains its value when local function are entered or exited. Global variables are set to zero at program startup.

FB places an implicit begin globals statement at the beginning of your program. That means that, by default, all variables declared in "main" are global. You must include an end globals statement in "main" if you want any of the variables declared in "main" to be local to "main."

By judicious placement of begin globals...end globals statements, you can also create variables which are considered "global" to some local functions but not to others.
begin globals and end globals are "non-executable" statements, so you can't change their effect by putting them inside a conditional execution structure such as long if...end if. However, you can conditionally include or exclude them from the program by putting them inside a #if block.
You may include any number of begin globals...end globals pairs in your program. You may also include begin globals...end globals pairs in local functions. They must occur in matched pairs when they occur within a local function, and should normally be in matched pairs when they occur in the "main" part of your program (the "main" part consists of those lines which are outside of all local functions). When you include a begin globals...end globals section in "main," it should not enclose any local functions, or variables may be scoped in unpredictable ways.
When a variable's first appearance within "main" occurs within a begin globals...end globals section, that variable is declared as global to all local functions which appear below that section.

See Also:
end globals