Appendix D. Variable Scope

The rule of variable scope is defined simply: a variable created inside a block (code enclosed within braces: { and }) exists only inside that block. This means that a variable created inside setup() can be used only within the setup() block, and likewise, a variable declared inside draw() can be used only inside the draw() block. The exception to this rule is a variable declared outside of setup() and draw(). These variables can be used in both setup() and draw() (or inside any other function that you create). Think of the area outside of setup() and draw() as an implied code block. We call these variables global variables, because they can be used anywhere within the program. We call a variable that is used only within ...

Get Getting Started with Processing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.