new mexico computer science for all local variables in netlogo maureen psaila-dombrowski
TRANSCRIPT
![Page 1: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/1.jpg)
New Mexico Computer Science For All
Local Variables in Netlogo
Maureen Psaila-Dombrowski
![Page 2: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/2.jpg)
Variables in Computer Science
•A variable is a container that holds a value
•It has the following fixed properties A name, used in the program to access
the value. A type (number, text, boolean, etc.) A physical location in memory
•The value stored in the variable can be used and changed as the program is executed
![Page 3: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/3.jpg)
Steps for Using Variables
•Three Steps for Using Variables
▫Declare – allocates the space for the variable and sets the name given to the variable
▫Initialize – set the initial value of the variable
▫Call/Modify – Use it in the program or change the value stored in the variable as the program is executed
![Page 4: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/4.jpg)
Local Variables
•A local variable is a variable that can only be used in the procedure or command block where it is declared.
•Cannot be accessed by the program in other locations
![Page 5: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/5.jpg)
Local Variables in NetLogo
•Declare and initialize local variables using the let command
example: let newvar 15
▫Declares a variable named newvar and initializes to 15
![Page 6: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/6.jpg)
Local Variables in NetLogo
•Call a local variable
example: set color newvar
▫Sets the color of the turtle to color 15 (red)
•Modify a local variable using the set command
example: set newvar 25
▫Modifies the value of newvar to 25
![Page 7: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/7.jpg)
NetLogo Example: Distance from (0,0)
•Setup Procedure▫Clears the NetLogo world, creates 50 turtle,
scatters them and colors them red▫Set the color of turtle #1 to white
![Page 8: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/8.jpg)
NetLogo Example: Distance from (0,0)
•Walk Procedure▫ Declares and initializes the variable “dist”▫ Moves all turtles forward 1 step▫ Modifies the value of “dist” to be the distance of
turtle #1 from the origin▫ Prints
![Page 9: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/9.jpg)
NetLogo Example: Distance from (0,0)
•Walk Procedure▫ Declares and initializes the variable “dist”▫ Moves all turtles forward 1 step▫ Modifies the value of “dist” to be the distance of
turtle #1 from the origin▫ Prints
![Page 10: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/10.jpg)
NetLogo Example: Distance from (0,0)
![Page 11: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/11.jpg)
Summary•A variable is a named memory location
▫Holds a value▫Value can used and/or changed as the
program is executed
•Three steps for using variables▫Declare▫Initialize▫Call/Modify
•A Local Variable used locally in the program where it is declared (procedure or command block)
![Page 12: New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski](https://reader036.vdocuments.mx/reader036/viewer/2022072005/56649cea5503460f949b5e0e/html5/thumbnails/12.jpg)
Further Information
•If you would like more information:
▫NetLogo Manual
▫NetLogo Dictionary