8.2. Using Repetition with TurtlesΒΆ
While learning how to draw with the turtle, we have found many reasons to repeat ourselves in
ways that a loop can make easier. A simple example is a square
procedure - it needs to
do both forward
and right
4 times. So why not have a for
loop repeat those for us:
The following program should define a procedure triangle that uses a loop to help draw a triangle. The main part of the program calls that function twice to draw two different triangles.
Arrange and indent the blocks correctly. You will not need them all.
The following program uses a turtle to draw a 175x150 rectangle as shown below, but the lines
are mixed up. We want to define a rectangle
procedure that repeats twice the process to draw
half of a rectangle: draw a line for the width, then turn, draw a line for the height, and
turn again.
Arrange the blocks into the correct solution and indent them properly. You will not use all of the blocks.