8
New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Embed Size (px)

Citation preview

Page 1: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

New Mexico Computer Science For All

Statements and Expressions in NetLogo

Maureen Psaila-Dombrowski

Page 2: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Statements and Expressions

•Generally, a computer program is made up of two types of code:

▫Statements

▫Expressions

Page 3: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Statements

•A statement is the smallest independent unit of code

•Usually a statement produces an action

Page 4: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Statements in NetLogo: Commands

•Statements in NetLogo are called COMMANDS

•There are many pre-defined commands (primitives) in NetLogo

•Typically they begin with a verb, such as “create”, “forward”, “clear”, “hatch”....

ask turtles [ forward 1 ]

Page 5: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Expressions

• It is the smallest unit of calculation.

•Expression represents or evaluates to a value

▫Single values (values, constant or variable)

▫Combinations of values interconnected with operators (25+12, a+b, x=y+12), or functions

If more than one operation occurs in an expression, the order of operations is used to determine the order they are performed in.

•That value is what the computer uses instead of the expression.

Page 6: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Expressions in NetLogo

•Similar to other programming languages•Equals something (evaluates to

something)Expression What it evaluates to:

12460 12460

8+20 28

28/4 7

sqrt 16 4

57 > 12 true

180 < 25 false

Page 7: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Summary

•There are two types of code:

▫Statements or Commands in NetLogo The smallest independent unit of code Produces an action

▫Expressions The smallest unit of calculation Produces (or evaluates to) a value

Page 8: New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski

Further Information

•If you would like more information:

▫NetLogo Manual

▫NetLogo Dictionary