Futurebasic/Language/Reference/begin globals

Statement
✔ Appearance ✔  Standard ✔  Console

Syntax
begin globals [statements including variable declarations] end globals

Description
The  and   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 is, it maintains its value when local function are entered or exited. By judicious placement of  statements, you can also create variables which are considered "global" to some local functions but not to others.

and  are "non-executable" statements, so you can't change their effect by putting them inside a conditional execution structure such as. However, you can conditionally include or exclude them from the program by putting them inside a  block.

You may include any number of  pairs in your program, although typically global variables are all defined within a single section near the beginning of the program. You may also include  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  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  section, that variable is declared as global to all local functions which appear below that section. All other variables in "main" are local to "main." Important: FB places an "implicit"  statement at the beginning of your program. That means that, by default, all variables declared in "main" are global. You must include an  statement in "main" if you want any of the variables declared in "main" to be local to "main."

When a variable's first appearance within a local function occurs within a  section, that variable is declared as global to that function and to all local functions which appear below that function. That variable is also global in "main," if its first appearance in "main" occurs below the function in which the variable was declared global. All other variables in the local function are local to that function, unless they were declared global in some preceding  section.