Week 02
Week 02
Week 2
(more) Basics of Programming
(a) 0 1
(b) 0 2 -These Multiple-Choice Questions
are not assessed. They are just quick
(c) 1 2
questions to test your own understanding.
(d) 0 1 2
(e) None of the above
Array
• Useful for storing multiple values
• Compare between these two examples to store values
and compute their average:
Array
• Example to draw the array values
STRUCTURE AND FLOW OF PROGRAM
- void setup(): called first and called one time. Usually
we put the functions to initialize the settings there.
For example, size(), background(), fill(), etc.
- void draw(): continuously run the lines in this
function until the program is stopped, or noLoop() is
called.
UNSTRUCTURED PROGRAM
- Does not contain setup() and draw()
functions
- "Static" only: no motions and no user
interaction
EXAMPLE 1 WHERE TO PUT BACKGROUND()?
Compare these two:
EXERCISE 1
Y-axis
(0,0) X-axis
Y-axis
Multiple-Choice Question
(a) (0,0)
(b) (50,50)
(c) (250,250)
(d) (350,350)
(e) (450,450)
Multiple-Choice Question
How many values are there in the
variable “array2D” after running
the code on the right?
(a) 9
(b) 10
(c) 81
(d) 100
(e) 200
Multiple-Choice Question
How many times is the factorial
function actually called in the
code on the right?
(a) 0
(b) 1
(c) 3
(d) 5
(e) 10
Class (a group of related variables, and
functions to compute something with them)