How do we use code to tell a computer this: “Create a variable and call a function 15 times”?
We could write it out 15 times:
create a variable call a function create a variable call a function create a variable call a function....
…We’ll spare you the rest. This approach takes a long time and it can easily lead to mistakes. Instead, let’s give the instructions once and tell the computer how many times to repeat them:
Repeat this 15 times: create a variable call a function
This structure is called a loop, and you’ll learn all about them in this lesson. These special structures in programming will give you the ability to repeat instructions multiple times without writing the instructions out multiple times.
This lesson will cover:
By the way, we assume that you’re familiar with creating variables, using operators, calling functions, and working with lists.
Create a pattern WITHOUT loops: In the text box, repeat these instructions 10 times, then run it:
If you did it correctly, you’ll see all 30 tiles placed on the board!