|
|
Each program can have only one setup() and one draw(). When the program starts, the code outside of setup() and draw() is run. Next, the code inside the setup() block is run once. After that, the code inside the draw() block is run continuously until the program is stopped.Because the variable y is declared outside of setup() and draw(), it’s a global variable and can be accessed and assigned anywhere within the program.
Variables declared within setup() can be accessed only within the setup() block. Variables declared within draw() can be accessed only within the draw() block. The scope of a variable declared within a block,called a local variable, extends only to the end of the block.
When a variable is created within a block, it is destroyed when the program leaves the block. For example, if a new variable is created inside an if block, it can be used within but cannot be accessed outside the block. If a new variable is used to iterate through a for structure, it can be used within but cannot be accessed outside the block. |
评分
-
查看全部评分
|