# Activity 2 - Simplifying code with loops

Great! You drew a square. But notice that we are writing the same lines over and over again! We had to repeat the instructions to draw a line and turn left 4 times. Wouldn’t it be great if we can give instructions once and tell the program to repeat it 4 times? Fear not, we can!

To do this, we need to use loops. Loops run a set of instructions multiple times. To see this in action, here is some example code that draws a triangle:

for i in range(3):
turtle.forward(50)
turtle.left(120)


Let’s understand what this code does. for i in range(3): This statement tells the program to run the instructions in a loop. range(3) sets a limit to how many times the loop runs (in this case, 3 times). The letter i is called a variable. It is used to keep track of how many times we have run the contents of the loop.

Now, take the example code that we have provided, and modify it slightly so that, instead of drawing a triangle, it draws a square. You can look back at what you did in Activity 1 as a hint.