The preceding code would declare a module variable called X, which can hold an integer data type. To create a module variable, you generally just declare a variable at the top of any file except you don’t use the Global or Public keyword. In some programming languages, you declare a module variable with the Private keyword.
Because global and module variables can be dangerous to use because any part of a program can change them too, most programmers use global and module variables sparingly. Most of the time, programmers declare variables within a subprogram. Therefore, the only code that can access that variable is inside the subprogram itself. To create a variable with subprogram scope, you have to declare your variable at the top of that particular subprogram.
The subprogram effectively isolates to that variable from any other part of your program. You can call a subprogram from any part of a program, even from within another subprogram. In the curly bracket language family, calling a subprogram is the same. Use the subprogram’s name as a command. If you’ve stored a subprogram in a separate file, you may need to go through two steps to call a subprogram. The Monster object might contain a private subprogram that calculates exactly how the Monster object moves.