9. Understanding Scope and Lifetime

What’s Scope?

In this chapter, you add an important building block to your programming foundation. Specifically, this chapter discusses when a variable or procedure is accessible to code in another procedure. Two interlocking concepts control which variables a procedure can use: the scope of a variable dictates its visibility to other code, and the lifetime of a variable dictates when it contains valid data. Although the examples use variables, the information in this chapter also applies to constants.

Most variables work within the confines of the procedure in which they’re declared. Sometimes you need ...

Get Business solutions Automating Microsoft now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.