Variables

Level:
Newbie

Sometimes, it’s necessary to draw a figure on a different scale. For example, if we want to draw a square with side
length 100, a square with side length 200 and a square with side length 50, we need actually three different
procedures for each square.

to square1

repeat 4 [forward 100 right 90]

end

to square2

repeat 4 [forward 200 right 90]

end

to square3

repeat 4 [forward 50 right 90]

end

repeat 4 [forward 100 right 90]

end

to square2

repeat 4 [forward 200 right 90]

end

to square3

repeat 4 [forward 50 right 90]

end

We can see immediately that it would be easier to define a single procedure waiting for an argument: the side length. For example, square 200 should draw a square with side length 200, square 100 should draw a square with side length 100 ... It’s time to introduce the variable notion!