Global Variables
A global variable can be accessed, changed,
or modified anywhere in the program.
Global Variables
A global variable can be accessed, changed,
or modified anywhere in the program.
Text of videoThe scope of a variable refers to where in the program that variable will be available. A variable is only available in the block of code where it is delared, that is it is local to that block of code.
A global variable is one that is not declared inside a procedure or function.
A global variable can be accessed, changed, or modified anywhere in the program.
Variables that are declared inside a procedure or function are local: they can only be used inside the procedure or function where they are declared.
We are going to create a counter program by making counter global.
The counter will be declared outside of the procedures, making it global. Write the code as shown in the video.
Experiment: Add a button to reset the counter to 0. Add a button to subtract 1.