Say It Once, Do It Four Times
Four sides of a square means typing the same two lines four times. That is a lot of typing. A repeat does it for you.
π‘ The idea
A repeat does the same work again and again, so you type less.
- repeat 4 means do it four times.
- The work to repeat goes inside the square brackets.
- repeat 4 [ forward 80 right 90 ] draws a whole square.
- Change the number in front to repeat more times or fewer.
- A repeat is called a loop.
π Words to know
- repeat
- do the same thing again and again
- loop
- a piece of code that repeats
- brackets
- the square marks that hold the repeated work
π Watch this
A whole square, made by one short line of code.
repeat 4 [ forward 80 right 90 ]
βοΈ Your turn
- Run it and count the sides of the square.
- Change repeat 4 to repeat 2. How much of the square is left?
- Change 80 to 150 to make a big square.
- Try repeat 6 [ forward 60 right 60 ] and see the new shape.
π― Challenge: Make a triangle. Repeat three times and turn 120 each time.
Show me one answer
repeat 3 [ forward 100 right 120 ]
Your program